(require (lib "animation.ss" "frtime")
(lib "etc.ss" "frtime"))
(define GRID-SIZE 8)
(define NEEDLE-LENGTH 10)
(define SPACING 25)
(define PI 3.1415626535)
(define (distance x1 y1 x2 y2)
(sqrt (+ (sqr (- x1 x2)) (sqr (- y1 y2)))))
(define (create-needle num)
(let* ([row (quotient num GRID-SIZE)]
[col (remainder num GRID-SIZE)]
[x (+ (* row SPACING) SPACING)]
[y (+ (* col SPACING) SPACING)]
[delta-x (- (posn-x mouse-pos) x)]
[delta-y (- (posn-y mouse-pos) y)]
[theta1 (atan (/ delta-y (exact->inexact delta-x)))]
[theta2 (- theta1 PI)]
[x1-pos (+ x (* NEEDLE-LENGTH (cos theta1)))]
[y1-pos (+ y (* NEEDLE-LENGTH (sin theta1)))]
[x2-pos (+ x (* NEEDLE-LENGTH (cos theta2)))]
[y2-pos (+ y (* NEEDLE-LENGTH (sin theta2)))]
[color-density (min 1 (/ (distance x1-pos y1-pos (posn-x mouse-pos) (posn-y mouse-pos)) 150.0))]
)
(make-line (make-posn x1-pos y1-pos)
(make-posn x2-pos y2-pos)
(make-rgb (- 1 color-density) 0 0))))
(define needles (build-list (sqr GRID-SIZE) create-needle))
(display-shapes needles)