[Fluxus] pfunc question
gabor papp
gabor.lists at mndl.hu
Wed Apr 1 05:48:49 PDT 2009
i'm trying to get accustomed to pfunc. i'm trying to use it to
interpolate between two sets of positions ("p0" and "p1"). i guess this
cannot be done with pdata-op. am i right? i had to use 3 pfuncs and 2
temporary pdata fields to do this. "t0" = (1 - t) * "p0", "t1" = t *
"p1", and "p" = "t0" + "t1". is there a simpler way?
best,
gabor
;----------------------------------
(clear)
(define p (build-particles 256))
(with-primitive p
; pdata storing positions to interpolate between
(pdata-add "p0" "v")
(pdata-add "p1" "v")
; random sphere
(pdata-map! (lambda (p) (srndvec)) "p0")
; random cube
(pdata-map! (lambda (p) (crndvec)) "p1")
; temporary data for interpolation
(pdata-add "t0" "v")
(pdata-add "t1" "v")
(pdata-map! (lambda (c) (vector 1 .5)) "c"))
(define p0f (make-pfunc 'arithmetic))
(define p1f (make-pfunc 'arithmetic))
(define pf (make-pfunc 'arithmetic))
; p = t0 + t1
(pfunc-set! pf (list 'operator "add"
'src "t0"
'other "t1"
'dst "p"))
(define (animate)
(let ([t (+ .5 (* .5 (sin (time))))])
; t0 = (1 - t) * p0
(pfunc-set! p0f (list 'operator "mul"
'src "p0"
'constant (- 1 t)
'dst "t0"))
; t1 = t * p1
(pfunc-set! p1f (list 'operator "mul"
'src "p1"
'constant t
'dst "t1"))
(with-primitive p
(pfunc-run p0f)
(pfunc-run p1f)
(pfunc-run pf))))
(every-frame (animate))
More information about the Fluxus
mailing list