;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;

;; BUBBLE TROUBLE

;;

;; Click and drag the mouse to create bubbles. You

;; might like to make the screen full size.

;; 

;; NOTES: Antialiasing has been turned off so we can draw

;;        over the previous path exactly. As an added

;;        bonus drawing speed is also increased.

;;        Try changing antialias off *aa-off* to *aa-on*

;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(define canvas (gfx:make-canvas))

(io:register-mouse-events canvas)

(gfx:clear-canvas (now) canvas '(1 1 1 1))

(gfx:set-alias #f)


; Note that gfx:draw-path uses *aa-off*

; *gfx:centre-scale* is needed by gfx:scale-path to

; ensure that the circles grow out from a central

; point.  Trying changing *gfx:centre-scale* to

; *gfx:bounds-scale* and *gfx:matrix-scale*

(define circles

   (lambda (time path cnt)

      (gfx:draw-path (+ time 0) canvas path 

                 '(0 0 0 1) '())            

      (gfx:scale-path (+ time 1) path 1.5 1.5 *gfx:centre-scale*)

      (gfx:draw-path (+ time 2) canvas path 

                 (list 1 1 1 1) '())

      (if (< cnt 12)

          (callback (+ time 3000) 'circles (+ time 6000) path (+ cnt 1)))))


; control the function with mouse gestures

(define io:mouse-down

   (lambda (x y)

      (circles (now) (gfx:make-circle x y 10) 0)))


(define io:mouse-drag

   (lambda (x y)

      (circles (now) (gfx:make-circle x y 10) 0)))