loadsa particles
This commit is contained in:
parent
057656012d
commit
c465ec71ae
3 changed files with 232 additions and 133 deletions
|
@ -38,15 +38,15 @@
|
|||
(rotate (vector 0 -90 0)))
|
||||
(else (rotate (vmul (crndvec) 20))))))
|
||||
|
||||
(define/public (update)
|
||||
(define/public (update t)
|
||||
|
||||
(for-each
|
||||
(lambda (child)
|
||||
(send child update))
|
||||
(send child update t))
|
||||
child-twigs)
|
||||
|
||||
(when (and (< age size) (< next-ring-time (time)))
|
||||
(set! next-ring-time (+ (time) speed))
|
||||
(when (and (< age size) (< next-ring-time t))
|
||||
(set! next-ring-time (+ t speed))
|
||||
(let ((p (with-state
|
||||
(parent root)
|
||||
(hint-depth-sort)
|
||||
|
@ -75,16 +75,84 @@
|
|||
|
||||
(super-new)))
|
||||
|
||||
(define pickup%
|
||||
(class object%
|
||||
(init-field
|
||||
(pos (vector 0 0 0)))
|
||||
(field
|
||||
(col (vmul (rndvec) 0.1))
|
||||
(root (let ((p (with-state
|
||||
(translate pos)
|
||||
(hint-depth-sort)
|
||||
(blend-mode 'src-alpha 'one)
|
||||
(texture (load-texture "textures/particle.png"))
|
||||
(build-particles 20))))
|
||||
(with-primitive p
|
||||
(pdata-add "vel" "v")
|
||||
(pdata-map!
|
||||
(lambda (vel)
|
||||
(vmul (vector (crndf) (* 2 (rndf)) (crndf)) 0.02))
|
||||
"vel")
|
||||
(pdata-map!
|
||||
(lambda (s)
|
||||
(vector 2 2 2))
|
||||
"s")
|
||||
(pdata-map!
|
||||
(lambda (c)
|
||||
col)
|
||||
"c"))
|
||||
p)))
|
||||
|
||||
(define/public (get-pos)
|
||||
pos)
|
||||
|
||||
(define/public (update t)
|
||||
(with-primitive root
|
||||
(pdata-op "+" "p" "vel")
|
||||
(pdata-op "*" "c" 0.996)
|
||||
(pdata-op "*" "s" 1.005)
|
||||
(when (zero? (random 5))
|
||||
(let ((reset (random (pdata-size))))
|
||||
(pdata-set! "c" reset col)
|
||||
(pdata-set! "p" reset (vector 0 0 0))
|
||||
(pdata-set! "s" reset (vector 2 2 2))))))
|
||||
|
||||
(super-new)))
|
||||
|
||||
(define seed%
|
||||
(class object%
|
||||
(field
|
||||
(twigs '())
|
||||
(pickups (build-list 10 (lambda (_)
|
||||
(make-object pickup% (vmul (vsub (crndvec) (vector 0 1 0)) 50)))))
|
||||
(indicator (let ((p (with-state
|
||||
(hint-depth-sort)
|
||||
;(blend-mode 'src-alpha 'one )
|
||||
(texture (load-texture "textures/particle.png"))
|
||||
(build-particles 200))))
|
||||
(with-primitive p
|
||||
(pdata-add "vel" "v")
|
||||
(pdata-map!
|
||||
(lambda (vel)
|
||||
(srndvec))
|
||||
"vel")
|
||||
(pdata-map!
|
||||
(lambda (c)
|
||||
(vector 0 0 0.1))
|
||||
"c")
|
||||
|
||||
(pdata-map!
|
||||
(lambda (s)
|
||||
(let ((sz (rndf)))
|
||||
(vector sz sz sz)))
|
||||
"s"))
|
||||
p))
|
||||
(debounce #t)
|
||||
(debounce-time 0)
|
||||
(pos (vector 0 0 0))
|
||||
(root (with-state
|
||||
(scale 5)
|
||||
(translate (vector 0 0 0))
|
||||
(translate pos)
|
||||
(texture (load-texture "textures/skin.png"))
|
||||
(backfacecull 0)
|
||||
(opacity 0.6)
|
||||
|
@ -100,22 +168,46 @@
|
|||
(send t build (vector 0 0 0) dir) t) twigs))))
|
||||
|
||||
|
||||
(define/public (update)
|
||||
(define/public (update t)
|
||||
|
||||
(let ((closest (foldl
|
||||
(lambda (pickup r)
|
||||
(if (< (vdist (send pickup get-pos) pos)
|
||||
(vdist pos r))
|
||||
(send pickup get-pos) r))
|
||||
(vector 999 999 999)
|
||||
pickups)))
|
||||
|
||||
(with-primitive indicator
|
||||
(pdata-op "+" "p" "vel")
|
||||
(when (< (sin (* 2 t)) 0)
|
||||
(let ((reset (random (pdata-size))))
|
||||
(let ((pos (vmul (vnormalise (vsub closest pos)) 10)))
|
||||
(pdata-set! "vel" reset (vadd (vmul (srndvec) 0.01)
|
||||
(vmul (vsub closest pos) (* (rndf) 0.01))))
|
||||
(pdata-set! "p" reset pos))))))
|
||||
|
||||
(with-primitive root
|
||||
(scale (+ 1 (* 0.001 (sin (* 2 t))))))
|
||||
|
||||
(when (key-pressed "r") (with-primitive camera (parent 1)))
|
||||
|
||||
(when (and debounce (key-pressed " "))
|
||||
(add-twig (vtransform-rot (vector 0 0 1) (minverse (get-camera-transform))))
|
||||
(set! debounce #f)
|
||||
(set! debounce-time (+ (time) 1)))
|
||||
(set! debounce-time (+ t 1)))
|
||||
|
||||
(when (> (time) debounce-time)
|
||||
(when (> t debounce-time)
|
||||
(set! debounce #t))
|
||||
|
||||
(for-each
|
||||
(lambda (twig)
|
||||
(send twig update))
|
||||
twigs))
|
||||
(send twig update t))
|
||||
twigs)
|
||||
(for-each
|
||||
(lambda (pickup)
|
||||
(send pickup update t))
|
||||
pickups))
|
||||
|
||||
(super-new)))
|
||||
|
||||
|
@ -222,4 +314,11 @@
|
|||
(fog (vector 0.2 0.5 0.3) 0.01 1 100)
|
||||
(define s (make-object seed%))
|
||||
|
||||
(every-frame (send s update))
|
||||
(define t 0)
|
||||
|
||||
(define (animate)
|
||||
(send s update t)
|
||||
(set! t (+ t 0.02)))
|
||||
|
||||
(every-frame (animate))
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 31 KiB |
BIN
plant-eyes/textures/particle.png
Normal file
BIN
plant-eyes/textures/particle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 36 KiB |
Loading…
Reference in a new issue