Created
November 15, 2011 20:25
-
-
Save ellbur/1368219 to your computer and use it in GitHub Desktop.
Triangles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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