1
1
(ns ex49-archimedean_spiral
2
- " Generates an archimedean spiral"
2
+ " Generates an archimedean spiral with an oscillating radius "
3
3
(:require [clojure2d.core :refer :all ]
4
- [fastmath.core :as m])
5
- ( :import [fastmath.vector Vec2 ]))
4
+ [fastmath.core :as m]
5
+ [fastmath.vector :as v ]))
6
6
7
7
; ; be sure everything is fast as possible
8
8
(set! *warn-on-reflection* true )
9
9
(set! *unchecked-math* :warn-on-boxed )
10
10
(m/use-primitive-operators )
11
11
12
- (def ^:const ^long fps 60 )
13
-
14
12
(def ^:const ^long w 800 )
15
13
(def ^:const ^long h 800 )
16
14
17
15
(def ^:const ^double x0 400 )
18
16
(def ^:const ^double y0 400 )
19
17
20
- (def ^:const ^double tStep 0.5 )
21
-
22
- (def ^:const ^double tAngleScale (/ m/PI 2 ))
23
- (def ^:const ^double tRadiusScale 10 )
24
-
25
- (defn draw [canvas window ^long frame _]
26
- (let [field (get-state window)
27
- t ^double (/ frame fps)]
28
- (-> canvas
29
- (set-background :black 50 )
30
- (set-color :white 80 ))
31
- (let [p (for [^double theta (range 0 t tStep)] (Vec2.
32
- (+ x0 (* (m/cos (* theta ^double tAngleScale)) (* theta tRadiusScale)))
33
- (+ y0 (* (m/sin (* theta ^double tAngleScale)) (* theta tRadiusScale)))))]
34
- (path-bezier canvas p false true ))))
35
-
36
- (def window (show-window {:canvas (canvas w h)
37
- :window-name " Archimedean spiral"
38
- :draw-fn draw
39
- :fps fps}))
18
+ (def ^:const ^double tStep 0.01 )
19
+
20
+ (def ^:const ^double tAngleScale m /HALF_PI )
21
+ (def ^:const ^double tRadiusScale 10.0 )
22
+
23
+ (def ^:const ^double ampFactor 0.3 )
24
+ (def ^:const ^double periodFactor 16 )
25
+
26
+ (defn draw [canvas window ^double frame _]
27
+ (let [t1 ^double (/ frame 60.0 )]
28
+ (-> canvas
29
+ (set-background :black 50 )
30
+ (set-color :white 80 ))
31
+ (let [p (for [^double t (range 0.0 t1 tStep)]
32
+ (let [theta (* t tAngleScale)
33
+ r (* (+ 1 (* ampFactor (m/sin (* periodFactor theta)))) (* t tRadiusScale))]
34
+ (vector (+ x0 (* (m/cos theta) r))
35
+ (+ y0 (* (m/sin theta) r)))
36
+ ))]
37
+ (path canvas p))))
38
+
39
+ (def window (show-window {:canvas (canvas w h :highest )
40
+ :window-name " Archimedean spiral with an oscillating radius"
41
+ :draw-fn draw}))
0 commit comments