Illusion of activity

Started by cormullion, December 18, 2007, 04:06:06 AM

Previous topic - Next topic

cormullion

How do I get this code to update every 500 milliseconds...? It only updates when I resize the window. I suppose that check-event doesn't run unless there's a mouse or keyboard event...?


(load (append (env "NEWLISPDIR") "/guiserver.lsp"))

(define (bar-output point-list)
(set 'x-coord 10  )
(dolist (y point-list)
    (gs:fill-rect "bar" x-coord
        (- window-height
            (int y)) bar-width
        (int y))
  (inc 'x-coord (+ bar-width 1))))

(gs:init)
(gs:frame 'f 50 50 640 660 )
(gs:set-background 'f 0.1 0.1 0.1)
(gs:canvas 'png)
(gs:set-paint gs:green)
(gs:set-translation 0 400)
(gs:add-to 'f 'png)
(gs:set-visible 'f true)
(set 'number-of-bars 50)
(map set '(x y window-width window-height) (gs:get-bounds 'f))
(set 'bar-width (/ window-width number-of-bars))
     
(while (gs:check-event 1000)
      (bar-output (random 0 window-height number-of-bars))
      (sleep 500)
      (gs:delete-tag "bar"))


Lutz

#1
This is how it will work:


(load (append (env "NEWLISPDIR") "/guiserver.lsp"))

(define (bar-output point-list)
   (set 'x-coord 10  )
   (dolist (y point-list)
    (gs:fill-rect "bar" x-coord
        (- window-height
            (int y)) bar-width
        (int y))
       (inc 'x-coord (+ bar-width 1))))

(gs:init)
(gs:frame 'f 50 50 640 660 )
(gs:set-background 'f 0.1 0.1 0.1)
(gs:canvas 'png)
(gs:set-background 'png 0 0 0) ;; CANVAS MUST HAVE A BACKGROUND COLOR
(gs:set-paint gs:green)
(gs:set-translation 0 400)
(gs:add-to 'f 'png)
(gs:set-visible 'f true)
(set 'number-of-bars 50)
(map set '(x y window-width window-height) (gs:get-bounds 'f))
(set 'bar-width (/ window-width number-of-bars))
     
(while (gs:check-event 1000)
      (bar-output (random 0 window-height number-of-bars))
      (gs:update) ;; UPDATE CANVAS AFTER DRAWING BEFORE SLEEPING
      (sleep 500)
      (gs:delete-tag "bar")
)


The upper-case commented lines are the once I added.



Lutz



ps: a canvas needs a background color to get erased properly, the gs:update insures that the changes are visible, only gs:xxx-tag operations to the update automatically

cormullion

#2
Ah - I knew that something had to have the background, but thought it was the frame not the canvas... Memory failing again, there... :)



Thanks again!