World w = new World ();
Turtle t = new Turtle (w);
int index;
// draw red square
t.setPenColor (Color.RED);
index = 0;
while ( index < 4 )
{
t.forward (100);
t.turn (-90);
index = index + 1;
}
// move to the right to draw second square
t.penUp();
t.turn (90);
t.forward (100);
t.penDown();
// draw blue square
t.setPenColor (Color.BLUE);
index = 0;
while ( index < 4 )
{
t.forward (100);
t.turn (-90);
index = index + 1;
}
// display the world
w.show();
public static void drawDecagon (Turtle t, int len, Color c)-- Main.troy - 2012-02-28
{
Color saved = t.getPenColor ();
t.setPenColor (c);
int index;
index = 0;
while ( index < 10 )
{
t.forward (len);
t.turn ( 360/10 ); // 36 degree turn
index = index + 1;
}
t.setPenColor (saved);
}
Copyright 2016 The Board of Trustees of the University of Illinois.webmaster@cs.uic.edu |
WISEST Helping Women Faculty Advance Funded by NSF | ![]() | ![]() |