[Fluxus] the end of push/pop?

Dave Griffiths dave at pawfal.org
Tue Oct 30 16:13:49 PDT 2007


Hi all,

So I'm leaving the flash graphics stuff for a bit and looking a bit more
at this scheme thing. :)

I've added a new and fairly untested set of higher level control
structures for manipulating objects and state in a cleaner and safer
manner. The first two make push/pop, grab/ungrab obsolete as suggested
some time ago. The second two are analogous to map and fold for lists
(but not exactly the same), and should make pdata modifications and
calculations simpler and a bit more expressive.


(with-state expression ...)
Returns: result of final expression
Description:
Encapsulates local state changes, and removes the need for push and pop.
Example:
; state hierachy, by nesting with-state:
(with-state
   (hint-vertcols)
   (colour (vector 0 0 1))
   (with-state
     (transform (vector 1 0 0))
     (build-sphere 10 10))
   (build-torus 1 2 30 30))

; making primitives is a bit simpler to read:
(define my-torus (with-state
   (hint-vertcols)
   (colour (vector 0 0 1))
   (build-torus 1 2 30 30)))

(with-primitive primitive expression ...)
Returns: result of last expression
Description:
Encapsulates primitive state changes, and removes the need for grab and
ungrab.
Example:  
(define my-torus (with-state
   (colour (vector 0 0 1))
   (build-torus 1 2 30 30)))

; change the torus colour: 
(with-primitive my-torus
   (colour (vector 0 1 0)))


(pdata-map! procedure read/write-pdata-name read-pdata-name ...)
Returns: void
Description:
A high level control structure for simplifying passing over pdata arrays
for primitive deformation. Should be easier and less error prone than
looping manually. Writes to the first pdata array.
Example:
(clear)
(define my-torus (build-torus 1 2 30 30))

;; jitter the vertices in x
(with-primitive my-torus
  (pdata-map!
    (lambda (position)
      (vadd position (vector (flxrnd) 0 0))) 
    "p")) ;; read/write the position pdata array

;; move the vertices along their normals
(with-primitive my-torus
  (pdata-map!
    (lambda (position normal)
      (vadd position normal)) 
    "p" "n")) ;; read/write the position pdata array, read the normals
array


(pdata-fold procedure start-value read-pdata-name)
Returns: result of folding procedure over pdata array
Description:
A high level control structure for doing calculations on pdata arrays. 
Runs the procedure over each pdata element accumulating the result.
Should be easier and less error prone than looping manually.
Example:  
(define my-torus (build-torus 1 2 30 30))

;; find the centre of the primitive by averaging 
;; the vertex position's together
(let ((centre 
   (with-primitive my-torus
     (vdiv (pdata-fold
       vadd
       (vector 0 0 0)
       "p") (pdata-size)))))
  
  (display centre)(newline))




More information about the Fluxus mailing list