Ronin experiment 15 - particles

Nikolaus Gradwohl2019-07-31T04:47:32+00:00

I have worked with particle systems a lot in processing, openframeworks and blender, so I had to experiment with one in ronin, exploring how particle states can be calculated in ronins lisp dialect.

particle system

So here is the first particle system in ronin - nothing fancy like boids yet, just simple particles bouncing of the world borders.

(def particles { :p () })

(defn init () (
  (set particles "p" (map (range 1 200) (lambda (a)
    {
      :id a
      :x (random 0 400)
      :y (random 0 400)

      :vx (random -1 1)
      :vy (random -1 1)

    }
  ))))
)

(defn update () (
  (each particles:p (lambda (p) (
      (set p "x" (add p:x p:vx))
      (set p "y" (add p:y p:vy))

      (if (lt p:x 10) (
        (set p "vx" (mul -1 p:vx))
        (set p "x" 10)
      ))
      (if (lt p:y 10) (
        (set p "vy" (mul -1 p:vy))
        (set p "y" 10)
      ))
      (if (gt p:x 390) (
        (set p "vx" (mul -1 p:vx))
        (set p "x" 390)
      ))
      (if (gt p:y 390) (
        (set p "vy" (mul -1 p:vy))
        (set p "y" 390)
      ))
  )))
))
(clear)
(resize 400 400)
(init)

(defn draw (p) (
(stroke
(fill
(circle p:x p:y 10)
 (rgba 100 200 100 0.8))
"white" 2)
))


(on "animate" '(
(clear)

(update)
(each particles:p (lambda (p) (
 (draw p)
)))
))
Tweet This! submit to reddit Digg! Tags: | no comments | no trackbacks

See also:

Ronin experiment 17 - boids
Ronin experiment 21 - morphing lissajous states
ronin experiment 20 - transform flower
ronin experiment 19 - Sonic Pi visualizer
Ronin experiment 18 - Rainbow

Trackbacks

Comments

Leave a response

Leave a comment