====== 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. {{::oldturtle1.png?400|}} 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. {{::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 the Java incarnation of Turtle Graphics. [[https://handwiki.org/wiki/Turtle_graphics|Read more about it here]] or [[https://en.wikipedia.org/wiki/Turtle_graphics|here]] ==== Java Console "Low-rez" Turtle ==== [[https://explained.blog/programming/program-for-turtle-graphics-game-in-java/|go to Assignment]] ==== 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-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: 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"); } } [[https://mathorama.com/mov/TurtleExample.mp4|Watch what this code does]]