2 * ASCII explosion from squeamish ossifrage at:
3 * https://codegolf.stackexchange.com/questions/24462/display-the-explosion-of-a-star-in-ascii-art/24554#24554
11 #define PERSPECTIVE 50.0
17 static double prng() {
19 s = s * 1488248101 + 981577151;
20 return ((s % 65536) - 32768) / 32768.0;
23 void draw_explosion(int i, int midx, int midy) {
24 static spaceblob_t blobs[NUM_BLOBS];
26 getmaxyx(stdscr,rows,cols);
27 int maxx,minx,maxy,miny;
34 /* Generate random blob coordinates */
35 for (int i=0; i<NUM_BLOBS; i++) {
40 br = sqrt(bx*bx + by*by + bz*bz);
41 blobs[i].x = (bx / br) * (1.3 + 0.2 * prng());
42 blobs[i].y = (0.5 * by / br) * (1.3 + 0.2 * prng());;
43 blobs[i].z = (bz / br) * (1.3 + 0.2 * prng());;
45 /* Flash on the first frame */
46 bkgd(COLOR_PAIR(WHITE_BG));
53 for (int y=miny; y<=maxy; y++) {
55 for (int x=minx; x<=maxx; x++) {
57 /* Show expanding star in next 7 frames */
59 double r = sqrt(x*x + 4*y*y);
65 /* Otherwise show blast wave */
66 double r = sqrt(x*x + 4*y*y) * (0.5 + (prng()/3.0)*cos(16.*atan2(y*2.+0.01,x+0.01))*.3);
70 int attr = 0;//color_ramp1[i-8];
71 line[col] = "%@W#H=+~-:."[i-8] | attr;
76 int attr = 0;//color_ramp2[v];
77 line[col] = " .:!HIOMW#%$&@08O=+-"[v] | attr;
84 mvaddchstr(row,0,line);
88 /* Add blobs with perspective effect */
91 for (int j=0; j<NUM_BLOBS; j++) {
92 double bx = blobs[j].x * i0;
93 double by = blobs[j].y * i0;
94 double bz = blobs[j].z * i0;
95 if (bz<5-PERSPECTIVE || bz>PERSPECTIVE) continue;
96 int x = midx + bx * PERSPECTIVE / (bz+PERSPECTIVE);
97 int y = midy + by * PERSPECTIVE / (bz+PERSPECTIVE);
98 if (x>=0 && x<cols && y>=0 && y<rows) {
100 mvaddch(row,col,(bz>40) ? '.' : (bz>-20) ? 'o' : '@');