Hi there fluxers,

Something odd is happening when I try and create custom pdata, following the example in the particles.scm file. I use pdata-set to create a pdata field called "age" which will be the particle age, and a field called "p-end" which will be the final position of the particle, but I am unable to alter the "age" or "p-end" fields (they are always 0) whereas I can alter the "p0" and the rest of the fields just fine. Try the code below - it will complain that "p-end" is not a vector in the (vdiv ...) function n (update)

(Note: this code is just to try things out - there are definitely better ways of doing this! I would NOT use this for any real purpose other than teaching / learning)



;--- begin moving-particles.scm  -------------

(clear)

(define particle-count 100)

(define stuff
    (with-state
        (hint-anti-alias)
        (build-particles particle-count)))


; init one particle
(define (init-particles n)
    (pdata-set "p" n (vector -10 0 0))
(pdata-set "p-end" n (vector (+ (* 10 (flxrnd)) 10) 0 (* 3 (flxrnd))))
    (pdata-set "age" n 0)
    (pdata-set "c" n (vector 1 1 1))
    (pdata-set "s" n (vector 1 1 1))
    (cond [(> n 0)
            (init-particles (- n 1))]
        [else 0])
    )

(with-primitive stuff
    (init-particles (pdata-size))
    (pdata-copy "p" "p0")
    )

(define (update p)
    (with-primitive p

        (pdata-map!
            (lambda (age)
                (modulo (+ age 1) 1000)) "age")

        (pdata-map!
            (lambda (p p0 p-end age)
                (vdiv (vsub p-end p0) age))
            "p" "p0" "p-end" "age")
        )
    )

(every-frame
    (update stuff))

Reply via email to