doomsday861 / THELOGOAPP

I'll probably be getting my hands dirty with Java this time. It will be an attempt to replicate the TURTLE game, we used to play in 5th grade maybe? But yeah, I will be using Java. Why>

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

THELOGOAPP

I'll probably be getting my hands dirty with Java this time. It will be an attempt to replicate the TURTLE game, we used to play in 5th grade maybe? But yeah, I will be using Java.

Why?

Because it has been sooooooo longgg that I have written anything in Java, and you know, Java is <3, plus I will have something interesting to do, when Graphs and Bits drive me nuts. And probably learn shiz I forgot, thats it bois!

Documentation Of TurtleGraphics

Class TurtleGraphics

  • java.lang.Object
    • java.awt.Component
      • java.awt.Container
        • javax.swing.JComponent
          • javax.swing.JPanel
            • uk.ac.leedsbeckett.oop.TurtleGraphics
  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible


    public class TurtleGraphics
    extends javax.swing.JPanel

    TurtleGraphics

    extended JPanel with simple drawing commands and a visual representation of a turtle to perform "turtle graphics" drawing operations. the jar file should be added to your build path. right click on your project, select "Build Path-Add External Archive" and add jar file. It will appear in your project explorer under "referenced libraries", inside the jar will be TurtleGraphics.class Don't forget to look at the inherited methods from JPanel and above, which will also be if use.
    Since:
    12/2018
    Version:
    1.5 Mar 2020 All software has bugs, if you find one please report to author. Ensure you have the latest version V1.3 adds setPanelSize() to resize the turtle area V1.4 adds getBufferedImage() *V1.5 adds setBufferdImage() V1.6 adds reset() to make resetting the turtle very, very easy.

    example code

    package whateverMyPackageIs;
    

    import uk.ac.leedsbeckett.oop.TurtleGraphics;

    import javax.swing.JFrame;

    public class MainClass {

        public static void main(String[] args) 
        {
                TurtleGraphics gp = new TurtleGraphics();
                JFrame MainFrame = new JFrame();
                MainFrame.add(gp);
                MainFrame.setSize(640, 480);
                MainFrame.setVisible(true);;
                gp.about();
    
        }
    

    }

    Author:
    Duncan Mullier
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      protected int direction
      direction the turtle is pointing in in degrees
      protected java.awt.Color PenColour
      Colour of the pen the turtle draws with (A Java Color)
      protected boolean penDown
      a moving turtle will draw if this is true and not if it is false (set by penDown and PenUp methods)
      protected int sleepPeriod
      delay for turtle animation
      protected int xPos
      x position of the turtle on the screen
      protected int yPos
      y position of the turtle on the screen
      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Constructor Summary

      Constructors 
      Constructor and Description
      TurtleGraphics()
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void about()
      draws a simple graphic on the canvas and reports the version number of this class
      void circle(int radius)
      unimplemented circle command
      void clear()
      Clears the image contents with the current background colour.
      void drawLine(java.awt.Color color, int x1, int y1, int x2, int y2)
      draws a line directly on the panel without affecting the turtle
      void forward(int distance)
      move the turtle (in the direction it is pointing) by {distance} pixels.
      java.awt.Color getBackground_Col()
      gets the background colour used by clear() to fill the panel.
      java.awt.image.BufferedImage getBufferedImage()
      return a BufferedImage of he display, so that it can be saved
      int getDirection()
      getDirection gets the direction the turtle is pointing in.
      java.awt.Graphics getGraphicsConext()
      returns the graphicsContext of the Turtle display so you can drw on it using the normal Java drawing methods
      java.awt.Graphics getGraphicsContext()
      returns the graphicsContext (same as above but spelt correctly) of the Turtle display so you can drw on it using the normal Java drawing methods
      java.awt.Color getPenColour()
      getPenColour returns the colour that the turtle draws in
      int getxPos()
      get the x position of the turtle
      int getyPos()
      get the y position of the turtle
      void paint(java.awt.Graphics g)
      overridden paint method to handle image updating (do not call directly, use repaint();)
      void penDown()
      puts pen down so a line will be drawn when the turtle is moved
      void penUp()
      puts pen up so a line will not be drawn when turtle is moved
      void reset()
      reset() moves turtle to initial position
      void setBackground_Col(java.awt.Color background_Col)
      sets the background colour used by clear() to fill the panel.
      void setBufferedImage(java.awt.image.BufferedImage newImage)
      sets the background image to be the passed in BufferedImage
      void setPanelSize(int xSize, int ySize)
      Resize the turtle area, current display will be lost.
      void setPenColour(java.awt.Color col)
      setPenColour sets the colour that the turtle will draw in
      void setPreferredSize(int width, int height) 
      void setTurtleImage(java.lang.String filename)
      Replace the standard turtle image with given image give full path or store in application directory don't make the image too big, have background of the image transparent and it should be pointing right (90 degrees) best to make the image have a transparent background(Google it).
      void setTurtleSpeed(int speed)
      sets the speed of the turtle's movement.
      void setxPos(int xPos)
      manually set the x position of the turtle (i.e.
      void setyPos(int yPos)
      manually set the y position of the turtle (i.e.
      void turnLeft()
      turtle is rotated 90 degrees to the left.
      void turnLeft(int amount)
      turtle is rotated 90 degrees to the right by amount degrees.
      void turnRight()
      turtle is rotated 90 degrees to the right.
      void turnRight(int amount)
      turtle is rotated 90 degrees to the right by amount degrees.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • PenColour

        protected java.awt.Color PenColour
        Colour of the pen the turtle draws with (A Java Color)
      • penDown

        protected boolean penDown
        a moving turtle will draw if this is true and not if it is false (set by penDown and PenUp methods)
      • xPos

        protected int xPos
        x position of the turtle on the screen
      • yPos

        protected int yPos
        y position of the turtle on the screen
      • direction

        protected int direction
        direction the turtle is pointing in in degrees
      • sleepPeriod

        protected int sleepPeriod
        delay for turtle animation
    • Constructor Detail

      • TurtleGraphics

        public TurtleGraphics()
        Constructor. Create a panel with pen set to the middle and turtle pointing down the screen The pen is up.
    • Method Detail

      • getGraphicsConext

        public java.awt.Graphics getGraphicsConext()
        returns the graphicsContext of the Turtle display so you can drw on it using the normal Java drawing methods
        Returns:
        graphics context
      • getGraphicsContext

        public java.awt.Graphics getGraphicsContext()
        returns the graphicsContext (same as above but spelt correctly) of the Turtle display so you can drw on it using the normal Java drawing methods
        Returns:
        graphics context
      • getBufferedImage

        public java.awt.image.BufferedImage getBufferedImage()
        return a BufferedImage of he display, so that it can be saved
        Returns:
        BufferedImage of display
      • setBufferedImage

        public void setBufferedImage(java.awt.image.BufferedImage newImage)
        sets the background image to be the passed in BufferedImage
        Parameters:
        newImage - saved BufferedImage
      • getPenColour

        public java.awt.Color getPenColour()
        getPenColour returns the colour that the turtle draws in
        Returns:
        Color pencolour
      • setPenColour

        public void setPenColour(java.awt.Color col)
        setPenColour sets the colour that the turtle will draw in
        Parameters:
        col - Java Color
      • getDirection

        public int getDirection()
        getDirection gets the direction the turtle is pointing in.
        Returns:
        direction in degrees
      • drawLine

        public void drawLine(java.awt.Color color,
                             int x1,
                             int y1,
                             int x2,
                             int y2)
        draws a line directly on the panel without affecting the turtle
        Parameters:
        color - colour to draw in
        x1 - xpos of start of line
        y1 - ypos of start of line
        x2 - xpos of end of line
        y2 - ypos of end of line
      • getBackground_Col

        public java.awt.Color getBackground_Col()
        gets the background colour used by clear() to fill the panel.
        Returns:
        the background_Col used when clear() is called.
      • setBackground_Col

        public void setBackground_Col(java.awt.Color background_Col)
        sets the background colour used by clear() to fill the panel.
        Parameters:
        background_Col - the background_Col to set (used when clear() is called.).
      • getxPos

        public int getxPos()
        get the x position of the turtle
        Returns:
        the xPos
      • setxPos

        public void setxPos(int xPos)
        manually set the x position of the turtle (i.e. lift the turtle up and drop it).
        Parameters:
        xPos - the xPos to set
      • getyPos

        public int getyPos()
        get the y position of the turtle
        Returns:
        the yPos
      • setyPos

        public void setyPos(int yPos)
        manually set the y position of the turtle (i.e. lift the turtle up and drop it).
        Parameters:
        yPos - the yPos to set
      • about

        public void about()
        draws a simple graphic on the canvas and reports the version number of this class
      • setTurtleSpeed

        public void setTurtleSpeed(int speed)
        sets the speed of the turtle's movement.
        Parameters:
        speed - 0 is fastest 1 for each microsecond of delay
      • penDown

        public void penDown()
        puts pen down so a line will be drawn when the turtle is moved
      • penUp

        public void penUp()
        puts pen up so a line will not be drawn when turtle is moved
      • turnRight

        public void turnRight()
        turtle is rotated 90 degrees to the right. i.e. if it is facing upwards (north) before it will facing right (east) after
      • turnRight

        public void turnRight(int amount)
        turtle is rotated 90 degrees to the right by amount degrees. i.e. it will rotate right by amount degrees The turtle will wrap around if it goes beyond 360
        Parameters:
        amount - degrees to rotate
      • turnLeft

        public void turnLeft()
        turtle is rotated 90 degrees to the left. i.e. if it is facing upwards (north) before it will facing left (west) after
      • turnLeft

        public void turnLeft(int amount)
        turtle is rotated 90 degrees to the right by amount degrees. i.e. it will rotate right by amount degrees The turtle will wrap around if it goes beyond 360
        Parameters:
        amount - degrees to rotate
      • forward

        public void forward(int distance)
        move the turtle (in the direction it is pointing) by {distance} pixels. A line will be drawn if the pen is down, not if it is up
        Parameters:
        distance - in pixels to move
      • clear

        public void clear()
        Clears the image contents with the current background colour.
      • circle

        public void circle(int radius)
        unimplemented circle command
        Parameters:
        radius - radius of the circle to draw
      • paint

        public void paint(java.awt.Graphics g)
        overridden paint method to handle image updating (do not call directly, use repaint();)
        Overrides:
        paint in class javax.swing.JComponent
      • setPreferredSize

        public void setPreferredSize(int width,
                                     int height)
      • setTurtleImage

        public void setTurtleImage(java.lang.String filename)
        Replace the standard turtle image with given image give full path or store in application directory don't make the image too big, have background of the image transparent and it should be pointing right (90 degrees) best to make the image have a transparent background(Google it).
        Parameters:
        filename - file or path to save the to
      • setPanelSize

        public void setPanelSize(int xSize,
                                 int ySize)
        Resize the turtle area, current display will be lost.
        Parameters:
        xSize - width of panel
        ySize - height of panel
      • reset

        public void reset()
        reset() moves turtle to initial position

About

I'll probably be getting my hands dirty with Java this time. It will be an attempt to replicate the TURTLE game, we used to play in 5th grade maybe? But yeah, I will be using Java. Why>


Languages

Language:Java 100.0%