Created
December 15, 2011 20:51
-
-
Save ellbur/1482810 to your computer and use it in GitHub Desktop.
Spiral
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 Spiral { | |
| public static void main(String[] args) { | |
| Drawing d = new Drawing(); | |
| spiral(d, 4); | |
| } | |
| static void spiral(Drawing d, int n) { | |
| // Base case | |
| if (n > 0) { | |
| // Make input smaller | |
| spiral(d, n-1); | |
| // Combine smaller step with current step | |
| d.drawLine(100 + -20*n+20, 100 + -20*n, 100 + 20*n, 100 + -20*n); | |
| d.drawLine(100 + 20*n, 100 + -20*n, 100 + 20*n, 100 + 20*n); | |
| d.drawLine(100 + 20*n, 100 + 20*n, 100 + -20*n, 100 + 20*n); | |
| d.drawLine(100 + -20*n, 100 + 20*n, 100 + -20*n, 100 + -20*n-20); | |
| } | |
| else { | |
| d.drawLine(100, 100, 100, 80); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment