Ronin experiment 16 - 3D box

Nikolaus Gradwohl2019-08-01T09:22:14+00:00

For this animation I pushed ronin to the next dimension and created a rotating 3D box

3D box

this is the code I used to rotate and project the cube

(def box (
({:x -10 :y -10 :z -10} {:x -10 :y 10 :z -10})
({:x -10 :y 10 :z -10} {:x 10 :y 10 :z -10})
({:x 10 :y 10 :z -10} {:x 10 :y -10 :z -10})
({:x 10 :y -10 :z -10} {:x -10 :y -10 :z -10})

({:x -10 :y -10 :z 10} {:x -10 :y 10 :z 10})
({:x -10 :y 10 :z 10} {:x 10 :y 10 :z 10})
({:x 10 :y 10 :z 10} {:x 10 :y -10 :z 10})
({:x 10 :y -10 :z 10} {:x -10 :y -10 :z 10})

({:x -10 :y -10 :z -10} {:x -10 :y -10 :z 10})
({:x -10 :y  10 :z -10} {:x -10 :y  10 :z 10})
({:x 10  :y  10 :z -10} {:x 10  :y  10 :z 10})
({:x 10  :y -10 :z -10} {:x 10  :y -10 :z 10})
))

(def d 50)

(defn roty (p a) {
  :x (add (mul p:x (cos a)) (mul p:z (sin a)))
  :y (mul p:y 1)
  :z (add (mul p:x (mul -1 (sin a))) (mul p:z (cos a)))
})

(defn rotz (p a) {
  :x (add (mul p:x (cos a)) (mul p:y (mul -1 (sin a))))
  :y (add (mul p:x (sin a)) (mul p:y (cos a)))
  :z (mul p:z 1)
})

(defn project (p) {
  :x (mul d (div p:x (add d p:z)))
  :y (mul d (div p:y (add d p:z)))
})

(defn draw () (
(each box (lambda (l) (
 (def o (mod (time 0.0005) TWO_PI))
 (def o2 (mod (time 0.0003) TWO_PI))
 (def a (project (rotz (roty (first l) o) o2)))
 (def b (project (rotz (roty (last l) o) o2)))
 (stroke
 (line a:x a:y b:x b:y)
 "white" 0.1)
)))
))

(on "animate" '(
 (resetTransform)
 (clear)
 (move 300 300)
 (scale 10)
 (draw)
))
Tweet This! submit to reddit Digg! Tags: | no comments | no trackbacks

See also:

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

Trackbacks

Comments

Leave a response

Leave a comment