Advertisement
Guest User

fibonacci

a guest
Mar 6th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. // Fibonacci Spiral
  2. // By Temi Taylor
  3. // When running main, n is how many numbers of the sequence it goes through
  4. public class Lies
  5. {
  6. private static void fibs(Turtle t, int n)
  7. {
  8. int[] x = new int[n];
  9. x[0] = 1;
  10. x[1] = 1;
  11. for (int i = 0; i < n; i ++)
  12. {
  13. if (i > 1)
  14. {
  15. x[i] = x[i-1] + x[i-2];
  16. }
  17. quart(t, x[i]);
  18. System.out.println(x[i]);
  19. }
  20. }
  21.  
  22. static void quart(Turtle t, double r)
  23. {
  24. for (int i = 0; i < 10; i += 1)
  25. {
  26. t.forward(3.14159265 * 0.5 * r);
  27. t.left(9);
  28. }
  29. }
  30.  
  31. public static void main(int n)
  32. {
  33. Turtle t = new Turtle();
  34. t.up();
  35. t.setPosition(0, 0);
  36. t.down();
  37. t.speed(5);
  38. fibs(t, n);
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement