User Tools

Site Tools


turtle_graphics

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
turtle_graphics [2022/08/27 11:59] frchristurtle_graphics [2024/09/12 14:27] (current) – [Make Your own Picture] frchris
Line 1: Line 1:
 ====== Turtle Graphics ====== ====== Turtle Graphics ======
  
-{{ ::jturtle-0.1.1.jar |jturtle.jar}} Library of classes to draw with a turtle.  You can get the latest version [[https://sourceforge.net/projects/jturtle/|here]] 
  
 ===== History ===== ===== History =====
  
-In the 1960s, an educational programming language called Logo was developed. It is best known for teaching programming with turtles! The turtles were graphical or robotic turtles that were controlled with simple commands like go forward or turn right. Here’s a photo of a robot turtle from the 1960s. +In the 1960s, an educational programming language called Logo was developed. It is best known for teaching programming with turtles! The turtles were graphical or robotic turtles that were controlled with simple commands like go forwardturn, raise and lower a pen.  Moving the turtle with the pen down would draw a picture. Here’s a photo of a robot turtle from the 1960s. 
  
 {{::oldturtle1.png?400|}} {{::oldturtle1.png?400|}}
Line 12: Line 11:
 {{::turtlegraphicshistory.jpg?400|}}  {{::screen_shot_2022-08-27_at_8.48.01_am.png?400|}} {{::turtlegraphicshistory.jpg?400|}}  {{::screen_shot_2022-08-27_at_8.48.01_am.png?400|}}
  
 +This was later used (in a simulated state) to teach newer programming languages as they get invented. Here we have two Java incarnations of Turtle Graphics.
  
 +[[https://handwiki.org/wiki/Turtle_graphics|Read more about it here]] or [[https://en.wikipedia.org/wiki/Turtle_graphics|here]]
  
 +===== The CSAwesome Turtle =====
 +
 +[[https://github.com/bhoffman0/CSAwesome/raw/master/_sources/Unit2-Using-Objects/TurtleJavaSwingCode.zip|TurtleJavaSwingCode.zip]] has the Sources needed to make turtles with your own code on your own machine.  See Section 2.1 of the [[http://runestone.academy|Runestone Academy]] Book [[https://runestone.academy/ns/books/published/csawesome/index.html?mode=browsing|CSAwsome]]. 
 +
 +Here is the class diagram of ''SimpleTurtle'' the superclass of ''Turtle'' any subclass of ''SimpleTurtle'' has these attributes and methods:
 +{{::superturtle_class_diagrampng.png?400|}}
 +
 +
 +The class Main has the main method
 +<code java>
 +public class Main {
 +  public static void main(String[] args) {  
 +    World world = new World(400,400);
 +    Turtle yertle = new Turtle(world);
 +    // Add your own code in here 
 +    world.setVisible(true);
 +    yertle.setColor(Color.blue);
 +    yertle.forward();
 +    yertle.turnRight();
 +    yertle.forward();
 +    
 +    
 +  }
 +}
 +</code>
 +
 +
 +===== Java "Animated" APLU Turtle =====
 +An animated version from Berne, Switzerland has so many classes, they put them all in a Library.  This library is in a file called {{ ::jturtle-0.1.1.jar |jturtle-0.1.1.jar}}.  [[https://mathorama.com/wiki/doku.php?id=how_to_install_the_library_in_bluej| Click here for instructions on how to install it in BlueJ]], and [[https://mathorama.com/wiki/doku.php?id=how_to_install_the_library_in_eclipse|click here for instructions to install a .jar library in Eclipse]]
 +
 +The [[http://www.aplu.ch/home/apluhomex.jsp?site=65|APLU.ch]] Java Utility Package **ch.aplu.turtle** Description
 +
 +The Java Turtle Package provides functionality for LOGO-like Java-Programs (including multiple turtles). It is written for educational purposes by Regula Hoefer-Isenegger for the AHL at the University of Berne under the supervision of Prof. Dr. Aegidius Plüss. 
 +The Java Turtle Package comes under the GNU GENERAL PUBLIC LICENSE, Version 2, June 1991 (which you can find in the COPYING file which comes along with this package) and is copyrighted by the author. 
 +
 +
 +You will need download this jar file and add it to your Libraries (Java Build Path in Eclipse, Library Tab in Preferences in BlueJ): 
 +
 +{{ ::jturtle-0.1.1.jar |jturtle-0.1.1.jar}} Library of classes to draw with a turtle.  You can get the latest version 21st Century version [[https://sourceforge.net/projects/jturtle/|here]]
 +
 +==== Make Your own Picture====
 +Here is an example of a Turtle instance that can make a hexagon, fill it in with a color, and "autographs" it:
 +
 +<code java>
 +import ch.aplu.turtle.*;
 +import java.awt.Color;
 +/**
 + 
 + * @author (Your Name)
 + * @version September 0, 2024
 + */
 +public class MyPicture {
 +
 + public static void main(String[] args) {
 +     
 +        Turtle hexter = new Turtle(Color.GREEN);
 +        
 +        hexter.setPos(100,-50);
 +       
 +        for (int i=0; i< 6; i++) {
 +        hexter.forward(100);
 +        hexter.right(-60);
 +        }
 +        
 +        hexter.setPos(0,0);
 +        hexter.setFillColor(Color.BLUE);
 + hexter.fill();
 +     
 +        Turtle t = new Turtle(hexter); 
 +        t.setPenColor(Color.RED);
 + t.setPos(-200, 180);
 + t.hideTurtle();
 +        t.label( "by My name");
 +     
 + }
 +
 +}
 +</code>
 +Here is the [[http://www.aplu.ch/classdoc/turtle/index.html|Turtle API]] (documentation in the Javadoc style) 
 +
 +The default turtle coordinate system: doubles -200.0..+200.0 in both directions (zero at center; x to left, y upward). (Turtle coordinates are rounded to to 400 x 400 pixel coordinates).
 +Unless special constructors are used, new turtles are shown in a new window. 
 +
 +Defaults when a turtle is created: 
 +Coordinates: (0, 0) (center of window)
 +Heading: north
 +Speed: 200 (coordinates per seconds)
 +
 +Lab Scoring:
 +  - Adds the [[https://www.mathorama.com/wiki/lib/exe/fetch.php?media=jturtle-0.1.1.jar|jturtle-0.1.1.jar]] library in either BlueJ or Eclipse
 +  - Your name as @author in a comment
 +  - The date as @version in a comment
 +  - Makes a Turtle that is visable
 +  - Draws a shape
 +  - Fills the shape with a color
 +  - Autographs their work with a label
 +  - (8th point: Has more than one shape with an additional Turtle instance
 +  - (9th or 10th point: Has unique and creative work of art
 +
 +Here's an example program which demonstrates how to use some of the fancy methods Turtle class from the APLU:
 +
 +<code java>
 +import ch.aplu.turtle.*;
 +import java.awt.Color;
 + 
 +public class Example
 +{
 +  public static void main (String[] args) {
 +    Turtle joe = new Turtle(Color.green); // Create a green turtle in her 
 +                                          //own window.
 +    joe.setPos(-100,100);                 // Place joe to the Point(-100,100).
 +    for (int i=0; i < 4; i++) {
 +      joe.right(90);
 +      joe.forward(200);                    // turn 90 degrees to the right, then 
 +                                          // move forward 200 pixels.
 +    }
 +    joe.setPenColor(Color.red);           // set the pen color to red.
 +    joe.penUp();                             // lifts the pen off the canvas pu() - pen up
 +    joe.back(50);
 +    joe.left(90);
 +    joe.back(50);
 +    joe.right(90);
 +    joe.penDown(); // back 50, left 90.... pen down
 +    for (int i=0; i < 4; i++) {
 +      joe.right(90);
 +      joe.forward(100);
 +    }
 +    Turtle anne = new Turtle(joe);        // Create a new Turtle (named anne)
 +                                          // in the same window as joe
 +    anne.speed(1000);// sets the speed to 1000 pixels/sec,
 +    anne.forward(150);
 +    anne.left(90);      
 +                                          // then do some moves.
 +    anne.hideTurtle();// ht(): hide the turtle
 +    anne.forward(150);
 +    anne.left(90);
 +    anne.stampTurtle(); 
 +    anne.forward(300);
 +    anne.showTurtle();                    // lets the turtle reappear on the  st(): show turtle
 +                                          // screen
 +    anne.wrap();                          // Tells anne to wrap around the edges
 +    anne.setPos(200,200);
 +    for (int i=0; i < 4; i++) {
 +      anne.right(90);
 +      anne.forward(400);
 +    }
 +    anne.reinit();                        // Resets anne to her standard settings,
 +                                          // e.g. home position,facing north 
 +    Turtle filly = new Turtle(joe, Color.yellow); // yellow Turtle in joe's
 +                                          // Playground.
 +    filly.setPos(75,75);
 +    filly.setFillColor(Color.black);      // Sets the fill color to black.
 +    filly.fill();                         // fills the region bounded by any 
 +                                          // non-background colored pixel, 
 +   // containing filly's position.
 +    filly.setPos(175,175);
 +    filly.setFillColor(Color.orange);
 +    filly.fill();
 + 
 +    Turtle texter = new Turtle(joe, Color.magenta);
 +    texter.hideTurtle().label("Hello Turtle");
 +  } 
 +}
 +</code>
 +
 +[[https://mathorama.com/mov/TurtleExample.mp4|Watch what this code does]]
  
  
  
turtle_graphics.1661615951.txt.gz · Last modified: 2022/08/27 11:59 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki