Turtle Graphics with Processing

http://cs.oregonstate.edu/~mjb/turtle


Latest update: April 18, 2024


Getting the Notes

Here are the notes: http://cs.oregonstate.edu/~mjb/turtle/turtle.pdf

Running the Web Version of Processing

Go here: https://editor.p5js.org/

Getting the Setup Code

Go here: https://cs.oregonstate.edu/~mjb/turtle/turtlesetup.html

What Functions Are Available?

F(p);Move forward by p pixels.
B(p);Move backwards by p pixels.
R(d);Turn to your right by d degrees.
L(d);Turn to your left by d degrees.
C(r,g,b);Set the color to r,g,b. Each of these numbers needs to be between 0 and 255.
W(p);Set the line width to p pixels.

Copy and Paste These Lines into the Editor

  1. Delete all the lines that are already in the program.
  2. Then go to https://cs.oregonstate.edu/~mjb/turtle/turtlesetup.html and copy-and-paste those lines into the program.

Now, click on the right-facing triangle to run the program.

Drawing a Branch

Copy-and-paste these lines to become the innards of the draw( ) function:


  var b = 100;
  F( b );
  R( 45 );
  F( b/2 );
  B( b/2 );
  L( 90 );
  F( b/2 );
  B( b/2 );
  R( 45 );
  B( b );
Then run the program.

Drawing Six Branches to Make a Snowflake

Copy-and-paste these lines to become the innards of the draw( ) function:


  var length = 100;
  for( var b = 0; b < 6; b = b + 1)
  {
    F( length );
    R( 45 );
    Branch( length/2 );
    L( 90 );
    Branch( length/2 );
    R( 45 );
    B( length );
    L( 60 );
  }
Then run the program.


Did you like these notes? Want to try some other fun K-12 stuff from Oregon State University?


Related college courses at Oregon State University:


For more information, contact:
Mike Bailey
Oregon State University
Professor, Computer Science
Kelley Engineering Center
Corvallis, OR 97331-0505
mjb@cs.oregonstate.edu