chapter.1.scm 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. (import
  2. (scheme base)
  3. (turtle simple))
  4. (define (squarepiece size)
  5. (forward size)
  6. (right 90))
  7. (define (tsquare size)
  8. (repeat (4)
  9. (squarepiece size)))
  10. (define (rectangle side1 side2)
  11. (repeat (2)
  12. (squarepiece side1)
  13. (squarepiece side2)))
  14. (define (try-angle side)
  15. (repeat (3)
  16. (forward side)
  17. (right 60)))
  18. (define (triangle side)
  19. (repeat (3)
  20. (forward side)
  21. (right 120)))
  22. (define (bad-house side)
  23. (tsquare side)
  24. (triangle side))
  25. (define (house side)
  26. (tsquare side)
  27. (forward side)
  28. (right 30)
  29. (triangle side))
  30. (define (circle radius)
  31. (repeat (36)
  32. (forward (* radius 0.17453))
  33. (right 10)))
  34. (define (circle2 square-side)
  35. (define c 0.09846965838363977)
  36. (repeat (36)
  37. (forward (* square-side c))
  38. (right 10)))
  39. (define (arcr r deg)
  40. (repeat ((/ deg 10))
  41. (forward (* r 0.17453))
  42. (right 10)))
  43. (define (arcl r deg)
  44. (repeat ((/ deg 10))
  45. (forward (* r 0.17453))
  46. (left 10)))
  47. (define (poly side angle)
  48. (repeat (100)
  49. (forward side)
  50. (right angle)))
  51. (define (polystop side angle)
  52. (let loop ((turn 0))
  53. (unless (and (= (modulo turn 360) 0)
  54. (> turn 0))
  55. (forward side)
  56. (right angle)
  57. (loop (+ turn angle)))))
  58. (define (newpoly side angle)
  59. (repeat (100)
  60. (forward side)
  61. (right angle)
  62. (forward side)
  63. (right (* 2 angle))))
  64. (define (newpolystop side angle)
  65. (let loop ((turn 0))
  66. (unless (and (= (modulo turn 360) 0)
  67. (> turn 0))
  68. (forward side)
  69. (right angle)
  70. (forward side)
  71. (right (* 2 angle))
  72. (loop (+ turn angle)))))
  73. (define (polyspi side angle inc)
  74. (define max-iters 100)
  75. (let loop ((iter 0)
  76. (side side))
  77. (when (< iter max-iters)
  78. (forward side)
  79. (right angle)
  80. (loop (+ iter 1) (+ side inc)))))
  81. (define (main)
  82. (set-pos 0 0)
  83. (clear-screen)
  84. (bg-color 'darkred)
  85. (line-color 'white)
  86. (polyspi 100 91 2))