Skip to content

Instantly share code, notes, and snippets.

@ellbur
Created November 15, 2011 20:25
Show Gist options
  • Select an option

  • Save ellbur/1368219 to your computer and use it in GitHub Desktop.

Select an option

Save ellbur/1368219 to your computer and use it in GitHub Desktop.
Triangles
public class Triangle {
public static void main(String[] args) {
Turtle.setSpeed(1000);
x(6);
}
static void x(int n) {
if (n == 0) {
Turtle.draw(3);
return;
}
else {
y(n-1);
Turtle.turn(60);
x(n-1);
Turtle.turn(60);
y(n-1);
}
}
static void y(int n) {
if (n == 0) {
Turtle.draw(3);
return;
}
else {
x(n-1);
Turtle.turn(-60);
y(n-1);
Turtle.turn(-60);
x(n-1);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment