Illusion of activity

Guiserver, GTK-server, OpenGL, PostScript,
HTML 5, MIDI, IDE
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Illusion of activity

Post by 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...?

Code: Select all

(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
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

This is how it will work:

Code: Select all

(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
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Post by cormullion »

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!

Locked