(gfx:draw-group time canvas paths strokes fills widths styles)


Draws a group of paths where paths is a vector of paths. strokes fills widths and styles are all flat vectors corresponding to paths. Fills and Strokes are flat vectors rgba.


         canvas -- the canvas to draw to

          paths -- a vector of paths to draw

          fills -- a flat vector of fill colours

        strokes -- a flat vector of stroke colours

           time -- time to draw group

         styles -- a vector of style values

         widths -- a vector of width values

Returns: boolean

Related: gfx:draw-image gfx:draw-path 


; set up graphics including vectors for paths, points, colours, styes etc.

(define canvas (gfx:make-canvas))

(gfx:clear-canvas (now) canvas '(0 0 0 1)) ; black background 

(define nodes 200) ; number of squares to animate 

(define size 5) ; square size 

; setup paths at random coordinates between 100,100 and 200,200

(define paths (make-vector-proc nodes

                                (lambda (i)

                                   (gfx:make-square (random 100 200)

                                                    (random 100 200)


; defaults for drawing path group

(define widths (make-vector nodes 1.0))

(define styles (make-vector nodes *gfx:stroke-path*)) ; stroke only 

; setup default colours 

(define fills (make-vector (* nodes 4))) ; we are not going to fill 

(define strokes (make-vector (* nodes 4)))

(vector= strokes 1.0 (list 0 nodes 4)) ; set red to 1.0 

(vector-rand strokes (list 1 nodes 4)) ; randomize green 

(vector= strokes 0.0 (list 2 nodes 4)) ; set blue to 0.0 

(vector= strokes 0.3 (list 3 nodes 4)) ; set alpha to 0.3 

; main animation loop

; NOTE: we could declare xpoints and ypoints globally and

; resuse these each time through loop in order to avoid

; constantly reallocating vector memory 

(define loop

   (lambda (time)

      (let ((xpoints (make-vector nodes))

            (ypoints (make-vector nodes)))

         (vector-rand xpoints) 

         (vector- xpoints 0.5) 

         (vector* xpoints 20.0)

         (vector-rand ypoints)

         (vector- ypoints 0.5)

         (vector* ypoints 20.0)

         (gfx:move-group time paths xpoints ypoints)

         (gfx:draw-group (+ time 5) canvas paths strokes fills widths styles)

         (callback (+ time 1000) 'loop (+ time 4410)))))

; start 

(loop (now))

Back to index