[q-lang-cvs] q/modules/ggi/examples flying_ggis.q,NONE,1.1 bufdemo.q,1.1,1.2 ggi_demo.q,1.3,1.4
Brought to you by:
agraef
From: <ag...@us...> - 2003-12-23 01:15:06
|
Update of /cvsroot/q-lang/q/modules/ggi/examples In directory sc8-pr-cvs1:/tmp/cvs-serv23691/modules/ggi/examples Modified Files: bufdemo.q ggi_demo.q Added Files: flying_ggis.q Log Message: major overhaul of GGI interface; see ChangeLog for details --- NEW FILE: flying_ggis.q --- /* $Id: flying_ggis.q,v 1.1 2003/12/23 01:15:02 agraef Exp $ */ /* flying_ggis.q: Another variation of the "Flying GGIs" theme. This one uses a custom font to render the text and an alpha buffer to make it translucent. (Requires FreeType and the GGI buffer extension.) */ /* Say `demo' to run. */ import ggi; // config section def // name of font file; edit this as needed FONT = "/usr/X11R6/lib/X11/fonts/truetype/times.ttf", // for some font types you also have to set a font metric file here FONT_METRIC = (), // face index (0 will do for most purposes) INDEX = 0; // globals def WD = 640, HT = 480, BD = 10, SZ = 50, RES = 72, PROB = 0.1, MAXN = 5, MAXS = min WD HT/SZ, MINV = 5, MAXV = 15; // color palette def COL = map color (nums 0 255), BLACK = hd COL, WHITE = last COL; color I = (shr I 5 and 7 * 0xffff div 7, shr I 2 and 7 * 0xffff div 7, I and 3 * 0xffff div 3); // initialize the display def VIS = ggi_open (), _ = ggi_set_mode VIS (sprintf "%dx%d" (WD,HT)) || ggi_set_flags VIS GGI_FLAG_ASYNC, // use a memory visual to reduce flickering MEM = ggi_open "memory", _ = ggi_set_mode MEM (sprintf "%dx%d.[C24/32].A16" (WD,HT)) || ggi_set_font MEM FONT INDEX || ggi_set_font_metric MEM FONT_METRIC || size SZ || fg BLACK 0xffff || bg WHITE 0 || clr; // adapt the maximum stretch according to the font def (W,H) = ggi_get_string_size MEM "GGI", MAXS = min (WD/W) (HT/SZ); // image descriptor: P = position, S = stretch, V = velocity (%), C = color type Image = image P S V C; // update the image list update IMGS = new (filter valid (map update1 IMGS)); update1 (image P S V C) = image P (S+V/100) V C; valid (image P S V C) = S<=MAXS; new IMGS = append IMGS (image (X,Y) 1.0 V C) where X = rand BD (WD-BD), Y = rand BD (HT-BD), V = rand MINV MAXV, C = COL!rand 0 254 if null IMGS or else (#IMGS < MAXN) and then (random/0xffffffff <= PROB); = IMGS otherwise; rand MIN MAX = MIN + random mod (MAX-MIN+1); // draw the image list draw IMGS = clr || do draw1 IMGS || show; draw1 (image P S V C) = fg C (round (0xffff/alpha S)) || size (round (S*SZ)) || center P "GGI"; alpha S = 1+(S-1)/(MAXS-1); // display operations fg C A = ggi_set_foreground MEM (append C A); bg C A = ggi_set_background MEM (append C A); clr = ggi_clear MEM; show = ggi_cross_blit MEM (0,0) (WD,HT) VIS (0,0) || ggi_flush VIS; size SZ = ggi_set_char_size MEM SZ RES; center (X,Y) S = ggi_puts MEM P S where (W,H) = ggi_get_string_size MEM S, P = (X - W div 2, Y - H div 2); // main loop loop IMGS = ggi_getc VIS || () if ggi_kbhit VIS; = draw IMGS || sleep 0.05 || loop (update IMGS) otherwise; demo = writes "Hit any key in the GGI window to stop\n" || loop []; Index: bufdemo.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/examples/bufdemo.q,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** bufdemo.q 15 Dec 2003 12:09:11 -0000 1.1 --- bufdemo.q 23 Dec 2003 01:15:02 -0000 1.2 *************** *** 1,7 **** ! /* bufdemo.q: Little alpha buffer demo, draws random rectangles with ! transparency until the user hits a key. 12-14-03, AG. Say `bufdemo' to ! run. NOTE: This script only works if you have the GGI buffer extension ! installed. */ import ggi; --- 1,8 ---- ! /* $Id$ ! ! bufdemo.q: Little alpha buffer demo, draws random boxes or lines with ! transparency until the user hits a key. Say `box_demo' or `line_demo' to ! run. */ import ggi; *************** *** 20,51 **** def COL = map color (nums 0 255), BLACK = hd COL, WHITE = last COL; ! color I = ggi_pixel (shr I 5 and 7 * 0xffff div 7, ! shr I 2 and 7 * 0xffff div 7, ! I and 3 * 0xffff div 3); ! /* Draw a rectangle with the given color and transparency. */ ! draw P DIM C A = ggi_set_foreground VIS C || ! ggi_set_alpha_foreground VIS A || ggi_draw_box VIS P DIM; ! /* Draw a random rectangle with random color and alpha. */ ! draw_rand = draw (X,Y) (W,H) C A where X = rand 10 (W-100), Y = rand 10 (H-100), W = rand 30 (min (W div 2) (W-X-10)), H = rand 30 (min (H div 2) (H-Y-10)), ! C = COL!rand 1 255, A = rand 1 0xffff; rand MIN MAX = MIN + random mod (MAX-MIN+1); ! /* The main function: Draw random rectangles until the user hits a key. */ ! bufdemo = show_msg || loop || hide_msg; ! loop = ggi_getc VIS || () if ggi_kbhit VIS; ! = draw_rand || loop otherwise; def MSG = "Running, hit a key to stop"; --- 21,74 ---- def COL = map color (nums 0 255), BLACK = hd COL, WHITE = last COL; ! color I = (shr I 5 and 7 * 0xffff div 7, ! shr I 2 and 7 * 0xffff div 7, ! I and 3 * 0xffff div 3); ! /* Draw a box with the given color and transparency. */ ! draw_box P DIM C ! = ggi_set_foreground VIS C || ggi_draw_box VIS P DIM; ! /* Draw a random box with random color and alpha. */ ! draw_rand_box = draw_box (X,Y) (W,H) (R,G,B,A) where X = rand 10 (W-100), Y = rand 10 (H-100), W = rand 30 (min (W div 2) (W-X-10)), H = rand 30 (min (H div 2) (H-Y-10)), ! (R,G,B) = COL!rand 1 255, ! A = rand 1 0xffff; ! ! /* Draw a line with the given color and transparency. */ ! ! draw_line P Q C = ggi_set_foreground VIS C || ! ggi_draw_line VIS P Q; ! ! /* Draw a random line with random color and alpha. */ ! ! draw_rand_line = draw_line (X1,Y1) (X2,Y2) (R,G,B,A) ! where X1 = rand 10 (W-10), ! Y1 = rand 10 (H-10), ! X2 = rand 10 (W-10), ! Y2 = rand 10 (H-10), ! (R,G,B) = COL!rand 1 255, A = rand 1 0xffff; rand MIN MAX = MIN + random mod (MAX-MIN+1); ! /* Draw random boxes until the user hits a key. */ ! box_demo = show_msg || box_loop || hide_msg; ! box_loop = ggi_getc VIS || () if ggi_kbhit VIS; ! = draw_rand_box || box_loop otherwise; ! ! /* Draw random lines until the user hits a key. */ ! ! line_demo = show_msg || line_loop || hide_msg; ! ! line_loop = ggi_getc VIS || () if ggi_kbhit VIS; ! = draw_rand_line || line_loop otherwise; def MSG = "Running, hit a key to stop"; *************** *** 54,60 **** ggi_set_foreground VIS WHITE || ggi_puts VIS (0,H-D) MSG ! where (_,D) = ggi_get_char_size VIS; hide_msg = ggi_set_foreground VIS BLACK || ggi_puts VIS (0,H-D) MSG ! where (_,D) = ggi_get_char_size VIS; --- 77,83 ---- ggi_set_foreground VIS WHITE || ggi_puts VIS (0,H-D) MSG ! where (_,D) = ggi_get_string_size VIS MSG; hide_msg = ggi_set_foreground VIS BLACK || ggi_puts VIS (0,H-D) MSG ! where (_,D) = ggi_get_string_size VIS MSG; Index: ggi_demo.q =================================================================== RCS file: /cvsroot/q-lang/q/modules/ggi/examples/ggi_demo.q,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ggi_demo.q 21 Dec 2003 11:05:29 -0000 1.3 --- ggi_demo.q 23 Dec 2003 01:15:02 -0000 1.4 *************** *** 1,5 **** /* ggi_demo.q: little demo of the ggi module, featuring a variation of the ! flying_ggis demo in the libggi distribution, 09-23-03, AG. */ /* Have CPU cycles to burn? ;-) Say `demo' to run. */ --- 1,6 ---- /* ggi_demo.q: little demo of the ggi module, featuring a variation of the ! flying_ggis demo in the libggi distribution. ! $Id$ */ /* Have CPU cycles to burn? ;-) Say `demo' to run. */ |