| Paste number 69811: | Fireworks |
| Pasted by: | tomppa |
| When: | 1 year, 8 months ago |
| Share: | Tweet this! | http://paste.lisp.org/+1HV7 |
| Channel: | #clojure |
| Paste contents: |
;; Vector ops go like this:
(defn #^floats v [x y]
[(float x) (float y)])
(defn #^Float vx [#^floats vec]
(vec 0))
(defn #^Float vy [#^floats vec]
(vec 1))
(defn #^floats v+ [#^floats a #^floats b]
[(+ (a 0) (b 0))
(+ (a 1) (b 1))])
(defn #^floats v- [#^floats a #^floats b]
[(- (a 0) (b 0))
(- (a 1) (b 1))])
(defn #^floats v* [#^floats vec #^Number m]
[(* (vec 0) (float m))
(* (vec 1) (float m))])
;; Main part
(defn update-point [p]
[(v+ (first p) (second p))
(v+ (v* (second p) 0.999) (v 0 0.1))])
(defn make-points [count pos]
(map (fn [_] [pos (v (- (rand 10) 5) (- (rand 10) 8))])
(range count)))
(defn main []
(with-screen "Foo" 800 600 false []
(with-update
(clear-screen +black+))
(loop [ps []]
(with-update
(clear-screen (color 0 0 0 32))
(set-color +yellow+)
(doseq p ps
(draw-line (first p) (v- (first p) (v* (second p) 2.0))))
(draw-fps)
(if (key-pressed? (vk ESCAPE))
(close-screen)))
(when (screen-running?) (recur (concat (make-points 10 (v 400 300))
(filter (fn [p]
(point-inside-rectangle? (first p)
(v 0 -100) 800 700))
(map update-point ps))))))))
This paste has no annotations.