Skip to content

Instantly share code, notes, and snippets.

@ellbur
Created December 15, 2011 20:51
Show Gist options
  • Select an option

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

Select an option

Save ellbur/1482810 to your computer and use it in GitHub Desktop.
Spiral
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