[Fluxus] ellipse (circle, really) primitive
evan.raskob [lists]
lists at lowfrequency.org
Wed Feb 4 10:58:06 PST 2009
hey y'all
Giving back to the list - I wrote some code to generate circles
(working on ellipses next). Here it is in progress... will post a
better version later when I adapt it to ellipses. For now, I learned
quite a bit about creating primitives. It could use some texture
data as well, but what the heck... I'm still new to scheme. In fact,
I spent way too much time thinking of how to build the vertices list
recursively (or functionally) using some elegant scheme but in the
end wound up doing it the way I would do it in Java or C++. Good
that scheme is flexible.
Cheers
Evan
;----- return a vector on a circle based on index
(define (calc-xyz index max-index r)
(let*
( [angle (* 6.28312 (/ index (- max-index 1)))]
[x (* (cos angle) r)]
[y (* (sin angle) r)] )
;(display (vector x y 0))(newline)
(vector x y 0))
)
(define (build-ellipse rmin rmaj num-verts)
(define p (build-polygons (* 3 num-verts) 'triangle-list))
(with-primitive p
(for ([i (in-range 0 (* 3 num-verts) 3) ])
(pdata-set! "p" i (vector 0 0 0))
(pdata-set! "n" i (vector 0 0 -1))
(pdata-set! "p" (+ i 1) (calc-xyz (/ i 3) num-
verts rmin))
(pdata-set! "n" (+ i 1) (vector 0 0 -1))
(pdata-set! "p" (+ i 2) (calc-xyz (+ (/ i 3) 1)
num-verts rmin))
(pdata-set! "n" (+ i 2) (vector 0 0 -1)))
(poly-convert-to-indexed)
)
p)
;---- this is handy for printing out all vertices
(define (show-pdata prm)
(with-primitive prm
(for ([i (in-range (pdata-size))])
(display (pdata-ref "p" i))(newline))
)
)
; (pdata-set! Name vertnumber vector)
More information about the Fluxus
mailing list