p5.turtle.js

Example of turtle graphics for p5.js

This is very simple and animated turtle graphics program. There are two step in the process. 1st step, it record turtle moving in setup(). 2nd step, it playback turtle moving for animation in draw(). This program needs p5.js and p5.play.js library.

View Source

Edit

Help

Get Started

1.Download

Download and Unzip this.

2.HTML

make html in the downloads and put this element in html

<div id = "p5Canvas"></div>

3.Javascript

put this library in html

<script src="js/p5.min.js"></script>
<script src="js/p5.play_patch119.js"></script>
<script src="p5.turtle.js"></script>

4.Edit turtle code

Edit your own turtle code in p5.turtle.js

// Start turtle code - recode turtle moving. -------------------------------------
turtle = new Turtle();
turtle.x = 140;
turtle.y = 80;
turtle.penDown = true;
turtle.penColor = turtle.color.blue;
for(var i = 0; i < 4; i++){
		turtle.forward(200);
		turtle.left(90);
};
turtle.right(360);
turtle.right(360);
// End of turtle code ------------------------------------------------------------

Example

Links