1 /**
2 ** colorops.c ---- test WRITE, XOR, OR, and AND draw modes
3 **
4 ** Copyright (c) 1995 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
5 ** [e-mail: csaba@vuse.vanderbilt.edu]
6 **
7 ** This is a test/demo file of the GRX graphics library.
8 ** You can use GRX test/demo files as you want.
9 **
10 ** The GRX graphics library is free software; you can redistribute it
11 ** and/or modify it under some conditions; see the "copying.grx" file
12 ** for details.
13 **
14 ** This library is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 **
18 **/
19
20 #include "test.h"
21 #include "rand.h"
22
TESTFUNC(colorops)23 TESTFUNC(colorops)
24 {
25 GrFBoxColors bcolors,ocolors,icolors;
26 GrColor bg,c;
27 int x = GrSizeX();
28 int y = GrSizeY();
29 int ww = (x * 2) / 3;
30 int wh = (y * 2) / 3;
31 int ii,jj;
32 int wdt = ww / 150;
33 int bw = x / 16;
34 int bh = y / 16;
35 int bx,by;
36
37 /* This won't work very well under X11 in pseudocolor
38 ** mode (256 colors or less) if not using a private
39 ** color map. The missing colors break RGB mode */
40 GrSetRGBcolorMode();
41
42 bcolors.fbx_intcolor = GrAllocColor(160,100,30);
43 bcolors.fbx_topcolor = GrAllocColor(240,150,45);
44 bcolors.fbx_leftcolor = GrAllocColor(240,150,45);
45 bcolors.fbx_rightcolor = GrAllocColor(80,50,15);
46 bcolors.fbx_bottomcolor = GrAllocColor(80,50,15);
47
48 ocolors.fbx_intcolor = GrAllocColor(0,120,100);
49 ocolors.fbx_topcolor = GrAllocColor(0,180,150);
50 ocolors.fbx_leftcolor = GrAllocColor(0,180,150);
51 ocolors.fbx_rightcolor = GrAllocColor(0,90,60);
52 ocolors.fbx_bottomcolor = GrAllocColor(0,90,60);
53
54 icolors.fbx_intcolor = GrAllocColor(30,30,30);
55 icolors.fbx_bottomcolor = GrAllocColor(0,180,150);
56 icolors.fbx_rightcolor = GrAllocColor(0,180,150);
57 icolors.fbx_leftcolor = GrAllocColor(0,90,60);
58 icolors.fbx_topcolor = GrAllocColor(0,90,60);
59
60 c = GrAllocColor(250,250,0);
61 bg = GrNOCOLOR;
62
63 for(ii = 0,by = -(bh / 3); ii < 17; ii++) {
64 for(jj = 0,bx = (-bw / 2); jj < 17; jj++) {
65 GrFramedBox(bx+2*wdt,by+2*wdt,bx+bw-2*wdt-1,by+bh-2*wdt-1,2*wdt,&bcolors);
66 bx += bw;
67 }
68 by += bh;
69 }
70
71 GrFramedBox(ww/4-5*wdt-1,wh/4-5*wdt-1,ww/4+5*wdt+ww+1,wh/4+5*wdt+wh+1,wdt,&ocolors);
72 GrFramedBox(ww/4-1,wh/4-1,ww/4+ww+1,wh/4+wh+1,wdt,&icolors);
73
74 GrSetClipBox(ww/4,wh/4,ww/4+ww,wh/4+wh);
75
76 drawing(ww/4,wh/4,ww,wh,c,bg);
77 while(!GrKeyPressed()) {
78 drawing(ww/4+(RND()%100),
79 wh/4+(RND()%100),
80 ww,
81 wh,
82 ((RND() / 16) & (GrNumColors() - 1)),
83 bg
84 );
85 }
86 GrKeyRead();
87 GrFramedBox(ww/4-1,wh/4-1,ww/4+ww+1,wh/4+wh+1,wdt,&icolors);
88 drawing(ww/4,wh/4,ww,wh,c,bg);
89 while(!GrKeyPressed()) {
90 drawing(ww/4+(RND()%100),
91 wh/4+(RND()%100),
92 ww,
93 wh,
94 ((RND() / 16) & (GrNumColors() - 1)) | GrXOR,
95 bg
96 );
97 }
98 GrKeyRead();
99 GrFramedBox(ww/4-1,wh/4-1,ww/4+ww+1,wh/4+wh+1,wdt,&icolors);
100 drawing(ww/4,wh/4,ww,wh,c,bg);
101 while(!GrKeyPressed()) {
102 drawing(ww/4+(RND()%100),
103 wh/4+(RND()%100),
104 ww,
105 wh,
106 ((RND() / 16) & (GrNumColors() - 1)) | GrOR,
107 bg
108 );
109 }
110 GrKeyRead();
111 GrFramedBox(ww/4-1,wh/4-1,ww/4+ww+1,wh/4+wh+1,wdt,&icolors);
112 drawing(ww/4,wh/4,ww,wh,c,bg);
113 while(!GrKeyPressed()) {
114 drawing(ww/4+(RND()%100),
115 wh/4+(RND()%100),
116 ww,
117 wh,
118 ((RND() / 16) & (GrNumColors() - 1)) | GrAND,
119 bg
120 );
121 }
122 GrKeyRead();
123 }
124
125