Changeset 1034 for libcaca/trunk/src
- Timestamp:
- Sep 16, 2006, 10:48:31 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/cacademo.c
r1032 r1034 32 32 enum action { PREPARE, INIT, UPDATE, RENDER, FREE }; 33 33 34 void do_transition(cucul_canvas_t *mask, int transition, float time); 34 35 void plasma(enum action, cucul_canvas_t *); 35 36 void metaballs(enum action, cucul_canvas_t *); … … 51 52 #define TRANSITION_FRAMES 40 52 53 54 #define TRANSITION_COUNT 2 55 #define TRANSITION_CIRCLE 0 56 #define TRANSITION_STAR 1 57 58 53 59 /* Common macros for dither-based demos */ 54 60 #define XSIZ 256 55 61 #define YSIZ 256 56 62 63 #define OFFSET_X(i) (i*2) 64 #define OFFSET_Y(i) (i*2)+1 65 66 float star[] = { 67 0.000000, -1.000000, 68 0.308000,-0.349000, 69 0.992000,-0.244000, 70 0.500000,0.266000, 71 0.632000,0.998000, 72 0.008000,0.659000, 73 -0.601000,0.995000, 74 -0.496000,0.275000, 75 -0.997000,-0.244000, 76 -0.313000,-0.349000 77 }; 78 79 57 80 /* Global variables */ 58 81 static int frame = 0; … … 65 88 int demo, next = -1, pause = 0, next_transition = DEMO_FRAMES; 66 89 unsigned int i; 90 int transition = cucul_rand(0, TRANSITION_COUNT); 91 92 67 93 68 94 /* Set up two canvases, a mask, and attach a display to the front one */ … … 90 116 fn[demo](INIT, frontcv); 91 117 92 for(;;) 118 for(;;) 93 119 { 94 120 /* Handle events */ … … 130 156 { 131 157 next = cucul_rand(0, DEMOS); 132 if(next == demo) 158 if(next == demo) 133 159 next = (next + 1) % DEMOS; 134 160 fn[next](INIT, backcv); … … 157 183 cucul_clear_canvas(mask); 158 184 cucul_set_color(mask, CUCUL_COLOR_WHITE, CUCUL_COLOR_WHITE); 159 cucul_fill_ellipse(mask, 160 cucul_get_canvas_width(mask) / 2, 161 cucul_get_canvas_height(mask) / 2, 162 cucul_get_canvas_width(mask) * 163 (frame - next_transition) / TRANSITION_FRAMES * 3 / 4, 164 cucul_get_canvas_height(mask) * 165 (frame - next_transition) / TRANSITION_FRAMES * 3 / 4, 166 "#"); 185 do_transition(mask, 186 transition, 187 (float)(frame - next_transition) / TRANSITION_FRAMES * 3.0f / 4.0f); 167 188 cucul_blit(frontcv, 0, 0, backcv, mask); 189 } else { 190 transition = cucul_rand(0, TRANSITION_COUNT); 168 191 } 169 192 … … 186 209 return 0; 187 210 } 211 212 /* Transitions */ 213 void do_transition(cucul_canvas_t *mask, int transition, float time) 214 { 215 float mulx = time*cucul_get_canvas_width(mask); 216 float muly = time*cucul_get_canvas_height(mask); 217 int w2 = cucul_get_canvas_width(mask) / 2; 218 int h2 = cucul_get_canvas_height(mask) / 2; 219 220 switch(transition) 221 { 222 case TRANSITION_STAR: 223 mulx*=1.8; 224 muly*=1.8; 225 cucul_fill_triangle(mask, 226 star[OFFSET_X(0)]*mulx+w2, star[OFFSET_Y(0)]*muly+h2, 227 star[OFFSET_X(1)]*mulx+w2, star[OFFSET_Y(1)]*muly+h2, 228 star[OFFSET_X(9)]*mulx+w2, star[OFFSET_Y(9)]*muly+h2, 229 "#"); 230 cucul_fill_triangle(mask, 231 star[OFFSET_X(1)]*mulx+w2, star[OFFSET_Y(1)]*muly+h2, 232 star[OFFSET_X(2)]*mulx+w2, star[OFFSET_Y(2)]*muly+h2, 233 star[OFFSET_X(3)]*mulx+w2, star[OFFSET_Y(3)]*muly+h2, 234 "#"); 235 cucul_fill_triangle(mask, 236 star[OFFSET_X(3)]*mulx+w2, star[OFFSET_Y(3)]*muly+h2, 237 star[OFFSET_X(4)]*mulx+w2, star[OFFSET_Y(4)]*muly+h2, 238 star[OFFSET_X(5)]*mulx+w2, star[OFFSET_Y(5)]*muly+h2, 239 "#"); 240 cucul_fill_triangle(mask, 241 star[OFFSET_X(5)]*mulx+w2, star[OFFSET_Y(5)]*muly+h2, 242 star[OFFSET_X(6)]*mulx+w2, star[OFFSET_Y(6)]*muly+h2, 243 star[OFFSET_X(7)]*mulx+w2, star[OFFSET_Y(7)]*muly+h2, 244 "#"); 245 cucul_fill_triangle(mask, 246 star[OFFSET_X(7)]*mulx+w2, star[OFFSET_Y(7)]*muly+h2, 247 star[OFFSET_X(8)]*mulx+w2, star[OFFSET_Y(8)]*muly+h2, 248 star[OFFSET_X(9)]*mulx+w2, star[OFFSET_Y(9)]*muly+h2, 249 "#"); 250 cucul_fill_triangle(mask, 251 star[OFFSET_X(9)]*mulx+w2, star[OFFSET_Y(9)]*muly+h2, 252 star[OFFSET_X(1)]*mulx+w2, star[OFFSET_Y(1)]*muly+h2, 253 star[OFFSET_X(5)]*mulx+w2, star[OFFSET_Y(5)]*muly+h2, 254 "#"); 255 cucul_fill_triangle(mask, 256 star[OFFSET_X(9)]*mulx+w2, star[OFFSET_Y(9)]*muly+h2, 257 star[OFFSET_X(5)]*mulx+w2, star[OFFSET_Y(5)]*muly+h2, 258 star[OFFSET_X(7)]*mulx+w2, star[OFFSET_Y(7)]*muly+h2, 259 "#"); 260 cucul_fill_triangle(mask, 261 star[OFFSET_X(1)]*mulx+w2, star[OFFSET_Y(1)]*muly+h2, 262 star[OFFSET_X(3)]*mulx+w2, star[OFFSET_Y(3)]*muly+h2, 263 star[OFFSET_X(5)]*mulx+w2, star[OFFSET_Y(5)]*muly+h2, 264 "#"); 265 break; 266 267 case TRANSITION_CIRCLE: 268 cucul_fill_ellipse(mask, 269 w2, 270 h2, 271 mulx, 272 muly, 273 "#"); 274 275 break; 276 277 } 278 } 279 188 280 189 281 /* The plasma effect */ … … 621 713 dir[a] = (dir[a] + 3) % 4; 622 714 screen[ax[a] + width * ay[a]] = (a << 4) | 0x0f; 623 } 715 } 624 716 ax[a] = (width + ax[a] + steps[dir[a]][0]) % width; 625 717 ay[a] = (height + ay[a] + steps[dir[a]][1]) % height;
Note: See TracChangeset
for help on using the changeset viewer.