1 /*
2 * BB: The portable demo
3 *
4 * (C) 1997 by AA-group (e-mail: aa@horac.ta.jcu.cz)
5 *
6 * 3rd August 1997
7 * version: 1.2 [final3]
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public Licences as by published
11 * by the Free Software Foundation; either version 2; or (at your option)
12 * any later version
13 *
14 * This program is distributed in the hope that it will entertaining,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILTY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17 * Publis License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include <string.h>
25 #include <stdlib.h>
26 #include <aalib.h>
27 #include "bb.h"
28 #include "image.h"
29
30 #ifdef ETIME
31 #undef ETIME
32 #endif
33 #define EFECT1 1
34 #define EFECT 2
35 #define EFECT2 6.0
36 #define ETIME EFECT*1000000
37 #define ETIME1 EFECT*1000000
38 #define MAXSHIFT (EFECT*400)
39 #define MAXRAND (EFECT*20)
40 #define N_STEP 30
41 #define MAXEFECT2 (N_STEP*EFECT2*20-N_STEP)
42
43 char *text;
44 static int cursorx, cursory;
45 void (*drawptr) ();
46
47 #define HEXA (rand()&2?'A'+rand()%6:'0'+rand()%10)
48
drawwait()49 static void drawwait()
50 {
51 aa_puts(context, (aa_scrwidth(context) - strlen(text)) / 2, aa_scrheight(context) / 2, AA_SPECIAL, text);
52 aa_flush(context);
53 }
54
55 static int bright = 255;
56
drawwait2()57 static void drawwait2()
58 {
59 int i = bright;
60 /*genwave(); */
61 if (i < 0)
62 i = 0;
63 centerprint(aa_imgwidth(context) / 2, aa_imgheight(context) / 3, 2, i, "AA", 0);
64 i = bright + 255;
65 if (i < 0)
66 i = 0;
67 if (i > 255)
68 i = 255;
69 centerprinth(aa_imgwidth(context) / 2, 2 * aa_imgheight(context) / 3, /*4 */ 8, i, "PRESENTS", 3);
70 }
71
72 static double pos, delta, dist;
73
drawwait4()74 static void drawwait4()
75 {
76 clrscr();
77 centerprint(aa_imgwidth(context) / 4 - dist * aa_imgwidth(context), pos, 1.1 + delta / 2, 255, "B", 0);
78 centerprint(3 * aa_imgwidth(context) / 4 + dist * aa_imgwidth(context), aa_imgheight(context) - pos, 1.1 + delta / 2, 255, "B", 0);
79 }
hlaska(char * text,float n)80 static void hlaska(char *text, float n)
81 {
82 clrscr();
83 centerprint(aa_imgwidth(context) / 2, aa_imgheight(context) / 2, n, 255, text, 3);
84 }
draw(void)85 void draw(void)
86 {
87 if (drawptr != NULL)
88 drawptr();
89 aa_render(context, params, 0, 0, aa_imgwidth(context), aa_imgheight(context));
90 aa_puts(context, (aa_scrwidth(context) - strlen(text)) / 2, aa_scrheight(context) / 2, AA_SPECIAL, text);
91 aa_flush(context);
92 }
93
calculateslow(int n)94 static void calculateslow(int n)
95 {
96 char a[2];
97 cursorx++;
98 if (cursorx >= aa_scrwidth(context)) {
99 cursory++;
100 cursorx = 1;
101 if (cursory >= aa_scrheight(context))
102 cursory = 0;
103 }
104 aa_gotoxy(context, cursorx, cursory);
105 a[0] = cursorx % 3 ? HEXA : ' ';
106 a[1] = 0;
107
108 aa_puts(context, cursorx - 1, cursory, AA_NORMAL, a);
109 }
110
111 static int randshift, randcharacters, randattrs;
112
drawline(int y)113 static void drawline(int y)
114 {
115 int x;
116 int shift = rand() % MAXSHIFT < randshift ? rand() : -1;
117 y *= aa_scrwidth(context);
118 for (x = 0; x < aa_scrwidth(context); x++) {
119 char c;
120 if (randattrs && (rand() % (MAXRAND) < randattrs)) {
121 continue;
122 }
123 else
124 context->attrbuffer[x + y] = AA_NORMAL;
125 if (randcharacters && rand() % MAXRAND < randcharacters)
126 continue;
127 else
128 c = (x - shift) % 3 ? HEXA : ' ';
129 context->textbuffer[x + y] = c;
130 }
131 }
132
drawwait3()133 static void drawwait3()
134 {
135 int y;
136 aa_render(context, params, 0, 0, aa_imgwidth(context), aa_imgheight(context));
137 for (y = 0; y < aa_scrheight(context); y++) {
138 drawline(y);
139 }
140 aa_puts(context, (aa_scrwidth(context) - strlen(text)) / 2, aa_scrheight(context) / 2, AA_SPECIAL, text);
141 aa_flush(context);
142 }
143
calculatefast(int n)144 static void calculatefast(int n)
145 {
146 int i;
147 if (randshift)
148 randshift += n;
149 for (i = 0; i < n; i++) {
150 drawline(cursory);
151 cursory++;
152 cursorx = 0;
153 if (cursory >= aa_scrheight(context))
154 cursory = 0;
155 }
156 aa_gotoxy(context, cursorx, cursory);
157 }
158
calculatefastest(int n)159 static void calculatefastest(int n)
160 {
161 if (randcharacters)
162 randcharacters += n;
163 if (randattrs)
164 randattrs += n;
165
166 }
167
decrandom(int n)168 static void decrandom(int n)
169 {
170 if (params->randomval > 0)
171 params->randomval -= n * N_STEP;
172 if (params->randomval < 60)
173 params->randomval = 60;
174 }
175
decbright(int n)176 static void decbright(int n)
177 {
178 bright -= n * 16;
179 }
180
181 double f = -10.0;
makepos(int n)182 static void makepos(int n)
183 {
184 int i;
185 for (i = 0; i < n; i++) {
186 f += (aa_imgheight(context) / 2 - pos) / 60;
187 f *= 0.95;
188 pos += f;
189 }
190 }
191
makepos1(int n)192 static void makepos1(int n)
193 {
194 int i;
195 for (i = 0; i < n; i++) {
196 f += (aa_imgheight(context) / 2 - pos) / 60;
197 f *= 0.95;
198 pos += f;
199 delta += 0.2;
200 }
201 }
202
makepos2(int n)203 static void makepos2(int n)
204 {
205 int i;
206 for (i = 0; i < n; i++) {
207 f += (aa_imgheight(context) / 2 - pos) / 60;
208 f *= 0.95;
209 pos += f;
210 delta -= 0.2;
211 if (delta <= 2)
212 delta = 0.1;
213 dist += 0.08;
214 }
215 }
216
strobikuj(int n)217 static void strobikuj(int n)
218 {
219 params->bright += n * 50;
220 }
221
strobikstart(void)222 void strobikstart(void)
223 {
224 int ditherbckup = params->dither;
225 if (context->driver->print != NULL)
226 params->dither = AA_NONE;
227 params->bright = 0;
228 timestuff(-60, strobikuj, draw, 1000000 / 15);
229 params->bright = 255;
230 params->dither = ditherbckup;
231 draw();
232 }
233
destrobikuj(int n)234 void destrobikuj(int n)
235 {
236 params->bright >>= n;
237 }
238
strobikend(void)239 void strobikend(void)
240 {
241 /*timestuff(60, destrobikuj, draw, 1000000 / 5); */
242 timestuff(-60, destrobikuj, draw, 1000000 / 3.5);
243 params->bright = 0;
244 draw();
245 }
246
blazinec()247 static void blazinec()
248 {
249 int i;
250
251 #define NTEXT sizeof(text)/sizeof(char *)
252
253 char *text[] =
254 {
255 "the",
256 "100 %",
257 "ANSI C",
258 "PORTABLE",
259 "DEMO",
260 ";^D",
261 "(^;",
262 "FULL",
263 "SVGA",
264 "TEXT",
265 "MODE",
266 "",
267 "DEVELOPED",
268 "UNDER",
269 "LINUX",
270 "!",
271 "!",
272 "!",
273 "?",
274 };
275 float sizes[] =
276 {
277 3,
278 3.5,
279 3.5,
280 4.2,
281 3,
282 2,
283 2,
284 3,
285 3,
286 3,
287 3,
288 1,
289 5,
290 3,
291 3,
292 1,
293 2,
294 3,
295 4.2,
296 };
297 if (context->driver->print != NULL)
298 params->dither = AA_NONE;
299 for (i = 0; i < NTEXT; i++) {
300 strobikstart();
301 params->randomval = 0;
302 hlaska(text[i], sizes[i]);
303 strobikend();
304 }
305 strobikstart();
306 params->dither = AA_FLOYD_S;
307 draw();
308 }
309
310 extern int dualmode;
311
vezen(struct image * i1,struct image * i2,struct image * i3,struct image * i4)312 void vezen(struct image *i1, struct image *i2, struct image *i3, struct image *i4)
313 {
314 drawptr = NULL;
315 dualmode = 0;
316 strobikstart();
317 clrscr();
318 dispimg(i1, dual);
319 strobikend();
320 bbwait(500000);
321 strobikstart();
322 clrscr();
323 dispimg(i2, dual);
324 strobikend();
325 bbwait(500000);
326 strobikstart();
327 clrscr();
328 dispimg(i3, dual);
329 strobikend();
330 bbwait(500000);
331 strobikstart();
332 clrscr();
333 dispimg(i4, dual);
334 if (dual)
335 dispimg(i4, dual);
336 strobikend();
337 draw();
338 bbupdate();
339 bbwait(1000000);
340 }
341
scene1(void)342 void scene1(void)
343 {
344 aa_showcursor(context);
345 textclrscr();
346 clrscr();
347 text = "Please wait. Precalculating data";
348 cursorx = cursory = 0;
349 bright = 255;
350 pos = delta = dist = 0;
351 f = -10.0;
352 randshift = randcharacters = randattrs = 0;
353 timestuff(-10, calculateslow, drawwait, ETIME1);
354 timestuff(-40, calculateslow, drawwait, ETIME1);
355 timestuff(-80, calculateslow, drawwait, ETIME1);
356 timestuff(-30, calculatefast, drawwait, ETIME1);
357 timestuff(-200, calculatefast, drawwait, ETIME1);
358 timestuff(-420, calculatefast, drawwait, ETIME);
359 randshift = 1;
360 timestuff(600, calculatefast, drawwait, ETIME1);
361 randshift = MAXSHIFT;
362 params->randomval = MAXEFECT2 + 50;
363 text = "";
364 aa_gotoxy(context, 0, 0);
365 aa_hidecursor(context);
366 timestuff(20, calculatefastest, drawwait3, ETIME);
367 timestuff(20, calculatefastest, drawwait3, ETIME);
368 randcharacters = 1;
369 timestuff(20, calculatefastest, drawwait3, ETIME);
370 randcharacters = MAXRAND;
371 randattrs = 1;
372 timestuff(20, calculatefastest, drawwait3, ETIME);
373 randattrs = MAXRAND;
374 timestuff(20, calculatefastest, drawwait3, ETIME);
375 drawptr = drawwait2;
376 play();
377 timestuff(20, decrandom, draw, EFECT2 * 1000000);
378 timestuff(20, decbright, draw, ETIME);
379 pos = aa_imgheight(context) * 2;
380 drawptr = drawwait4;
381 timestuff(60, makepos, draw, 5 * 1000000);
382 timestuff(60, makepos1, draw, 0.2 * 1000000);
383 timestuff(60, makepos2, draw, 0.3 * 1000000);
384 drawptr = NULL;
385 blazinec();
386 }
387
introscreen(void)388 void introscreen(void)
389 {
390 text = "Please wait. Precalculating data";
391 drawwait();
392 text = "";
393
394 }
395