User Tools

Site Tools


turtle_graphics

Turtle Graphics

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.

The turtle had a pen attached to it. The student-programmers would steer the robot around using simple commands to create drawings with their code.

This was later used (in a simulated state) to teach newer programming languages as they get invented. Here we have the Java incarnation of Turtle Graphics.

Read more about it here or here

Java Console "Low-rez" Turtle

Java "Hi Rez" Turtle

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.jar Library of classes to draw with a turtle. You can get the latest version here

Here's a simple sample program which shows how to use the Java Turtle Package:

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");
  } 
}

Watch what this code does

turtle_graphics.txt · Last modified: 2022/08/27 13:53 by frchris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki