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 13:25] – [Java "Hi Rez" Turtle] frchristurtle_graphics [2022/08/27 13:53] (current) frchris
Line 24: Line 24:
 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 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.  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. 
- 
-Here's a simple sample program which shows how to use the Java Turtle Package: 
  
  
 +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.jar}} Library of classes to draw with a turtle.  You can get the latest version [[https://sourceforge.net/projects/jturtle/|here]] {{ ::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]]
  
  
 +Here's a simple sample program which shows how to use the Java Turtle Package:
 +
 +<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.rt(90).fd(200);                 // turn 90 degrees to the right, then 
 +                                          // move forward 200 pixels.
 +    }
 +    joe.setPenColor(Color.red);           // set the pen color to red.
 +    joe.pu();                             // lifts the pen off the canvas pu() - pen up
 +    joe.bk(50).lt(90).bk(50).rt(90).pd(); // back 50, left 90.... pen down
 +    for (int i=0; i < 4; i++) {
 +      joe.rt(90).fd(100);
 +    }
 +    Turtle anne = new Turtle(joe);        // Create a new Turtle (named anne)
 +                                          // in the same window as joe
 +    anne.speed(1000).fd(150).lt(90);      // sets the speed to 1000 pixels/sec,
 +                                          // then do some moves.
 +    anne.ht().fd(150).lt(90).stampTurtle(); // ht(): hide the turtle
 +    anne.fd(300);
 +    anne.st();                            // 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.rt(90).fd(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.ht().label("Hello Turtle");
 +  } 
 +}
 +</code>
  
 +[[https://mathorama.com/mov/TurtleExample.mp4|Watch what this code does]]
  
turtle_graphics.1661621111.txt.gz · Last modified: 2022/08/27 13:25 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki