Fireworks

What would YOU do?

The no wind resistance parabolic arc is first.

Second I'm thinking simulating the entire rocket, including mass of propellant lost, propellant velocity, fuel mass lost...

Third, multi-stage fireworks that send multiple trailers out.

Next, wind to effect all the above...

Right now, it just clears the screen. I'll finish the parabola for sure though.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#define ESC char(27)
#define FUSEMIN 700
#define FUSEMAX 1200
//lets just send the thing on a parabolic curve for this version. like catapult fireworks. no wind resistance...
#define GRAV 0.001  //acceleration applied to velocity each FUSE tick 
#define YLAUNCHMAX 1 //fastest we want it going up.. or it'll skip boxes lol
#define YLAUNCHMIN .7 //slowest launch. too low and it'll fall back to earth undetonated...
#define XLAUNCHMAX .01
#define XLAUNCHMIN -.01 //These give angle so you see a parabola..


#define FLOOR 40 //y coordinate of the horizon
#define LAUNCHER 60 //x coordinate of the launcher & midscreen


using std::cout;

void vt100clear();
void vt100gotoxy(int x, int y);
void vt100setbackground(int c);
void vt100color(int x);



int main () {
	//the floats are for the math section and the horizon is at y=0 and the launcher is at x=0.
	//when converted to integers, the y coordinate is inverted and 0,0 is shifted to LAUNCHER,FLOOR
	float xvelocity=0,yvelocity=0;
	float xpos=0,ypos=0 ;
	vt100clear();
//math and such goes here.
	}

void vt100clear() {
	cout << ESC << "[2J" << ESC << "[f";
	}

void vt100gotoxy(int x, int y) {
	cout << ESC << "[" << y << ";" << x << "H";
	}

void vt100setcolor(int c) {
	cout << ESC << "[3" << c << "m" << c << "H";
	}

void vt100setbackground(int c) {
	cout << ESC << "[4" << c << "m" << c << "H";
	}
Last edited on
Launch code works but in these days of GHz processors spoiling all the fun, the whole thing just appears on the screen in the blink of an eye. I'll worry about that later. What matters is:
1. It's making nice arcs since I'm not erasing it as it moves.
2. I didn't do any math or anything to decide where its going. In the spirit of Mike Hughes and his steam powered rocket, I estimated everything then just adjusted it until it worked. That's what the debug lines are for: making sure I got reasonable values before I passed it to the graphics system. :-)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <ctime>

#define ESC char(27)
#define FUSEMIN 800
#define FUSEMAX 900
//lets just send the thing on a parabolic curve for this version. like catapult fireworks. no wind resistance...
#define GRAV 0.0001  //acceleration applied to velocity each FUSE tick 
#define YLAUNCHMAX .085 //fastest we want it going up..
#define YLAUNCHMIN .075 //slowest launch. too low and it'll fall back to earth undetonated...
#define XLAUNCHMAX .05
#define XLAUNCHMIN -.05 //These give angle so you see a parabola..

#define FLOOR 40 //y coordinate of the horizon
#define LAUNCHER 60 //x coordinate of the launcher & midscreen


using std::cout;

void vt100clear();
void vt100gotoxy(int x, int y);
void vt100setbackground(int c);
void vt100color(int x);



int main () {

	int x=0,y=0,c=0;
	int fuse, fuseloop=0;

	//the floats are for the math section and the horizon is at y=0 and the launcher is at x=0.
	//when converted to integers, the y coordinate is inverted and 0,0 is shifted to LAUNCHER,FLOOR
	float xvelocity=0,yvelocity=0;
	float xpos=0,ypos=0 ;

	vt100clear();
	srand(time(0));
	yvelocity= YLAUNCHMIN*1000 + rand()%1000*(YLAUNCHMAX-YLAUNCHMIN);
	yvelocity=yvelocity/1000;	
	xvelocity= XLAUNCHMIN*1000 + rand()%1000*(XLAUNCHMAX-XLAUNCHMIN);
	xvelocity=xvelocity/1000;	

	fuse= FUSEMIN*1000 + rand()%1000*(FUSEMAX-FUSEMIN);
	fuse= fuse/1000;	

	for (fuseloop=0; fuseloop < fuse; fuseloop++) {
		yvelocity-=GRAV;
		xpos+=xvelocity; ypos+=yvelocity;
//		cout << fuseloop << ": " << "yvelocity=" << yvelocity << "   xvelocity=" << xvelocity <<"\n";    //DEBUG LINE
//		cout << fuseloop << ": " << "xpos=" << xpos << "   ypos=" << ypos << "\n";  //DEBUG LINE	
		x=xpos+LAUNCHER; y=FLOOR-ypos; vt100gotoxy(x,y); 
		cout << "." ;
		}
	vt100gotoxy(1,FLOOR);
	}

void vt100clear() {
	cout << ESC << "[2J" << ESC << "[f";
	}

void vt100gotoxy(int x, int y) {
	cout << ESC << "[" << y << ";" << x << "H";
	}

void vt100setcolor(int c) {
	cout << ESC << "[3" << c << "m" << c << "H";
	}

void vt100setbackground(int c) {
	cout << ESC << "[4" << c << "m" << c << "H";
	}
made some stupid mistakes while copy/pasting and creating the color change code lol. they didnt trigger anything until I tried to actually use it.. first of all the vt100setcolor function isn't properly declared. second of all, the vt100 sequence is wrong for foreground and background (there's supposed to be nothing after the "m")...
Here's 5 animated fireworks slowed down enough to see the motion on a cheap, low end laptop. $150 newly used. If your desktop blinks thru it, increase the value of counter in the for loop for spinner.

It's running in a 160x50 text box so if you use a default console the resolution is gonna be too low. Gotta drag that window wider... or edit the code.

Looks alright by 1970s standards. Now they just need an explosion at the end. Or something. These just fade out into nothing.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <ctime>

#define ESC char(27)

#define FUSEMIN 800
#define FUSEMAX 1000
//lets just send the thing on a parabolic curve for this version. like catapult fireworks. no wind resistance...
#define GRAV 0.0001  //acceleration applied to velocity each FUSE tick 
#define YLAUNCHMAX .085 //fastest we want it going up..
#define YLAUNCHMIN .075 //slowest launch. too low and it'll fall back to earth undetonated...
#define XLAUNCHMAX .08
#define XLAUNCHMIN -.08 //These give angle so you see a parabola..

#define FLOOR 40 //y coordinate of the horizon
#define LAUNCHER 70 //x coordinate of the launcher & midscreen
#define BOMBS 5 //number to launch

using std::cout;

void vt100clear();
void vt100gotoxy(int x, int y);
void vt100setbackground(int c);
void vt100setcolor(int c);

void spinner(int x, int y);


int main () {

	int x=0,y=0,c=0;
	int fuse, fuseloop=0;
	int bombloop; 

	//the floats are for the math section and the horizon is at y=0 and the launcher is at x=0.
	//when converted to integers, the y coordinate is inverted and 0,0 is shifted to LAUNCHER,FLOOR
	float xvelocity=0,yvelocity=0;
	float xpos=0,ypos=0 ;

	vt100clear();
	srand(time(0));
	for (bombloop=0 ; bombloop < BOMBS; bombloop++) {
		xpos=0,ypos=0;
		yvelocity= YLAUNCHMIN*1000 + rand()%1000*(YLAUNCHMAX-YLAUNCHMIN);
		yvelocity=yvelocity/1000;	
		xvelocity= XLAUNCHMIN*1000 + rand()%1000*(XLAUNCHMAX-XLAUNCHMIN);
		xvelocity=xvelocity/1000;	

		fuse= FUSEMIN*1000 + rand()%1000*(FUSEMAX-FUSEMIN);
		fuse= fuse/1000;	
		for (fuseloop=0; fuseloop < fuse; fuseloop++) {
			yvelocity-=GRAV;
			xpos+=xvelocity; ypos+=yvelocity;
//			cout << fuseloop << ": " << "yvelocity=" << yvelocity << "   xvelocity=" << xvelocity <<"\n";    //DEBUG LINE
//			cout << fuseloop << ": " << "xpos=" << xpos << "   ypos=" << ypos << "\n";  //DEBUG LINE	
			x=xpos+LAUNCHER; y=FLOOR-ypos; 
			spinner (x,y); //draw the bomb
			vt100gotoxy(x,y); cout << "." ; //erase it with smoke
			}
		}
	vt100gotoxy(1,FLOOR);
	}

void spinner(int x, int y) {
	int counter=0, c=0;
	for (counter=0; counter < 100 ; counter++) {
		c=1+counter%6;
		vt100setcolor(c); //1-6, not black, not white.
		vt100gotoxy(x,y);
		cout << "O";	
		vt100gotoxy(x,y);
		cout << "-";	
		vt100gotoxy(x,y);
		cout << "/";	
		vt100gotoxy(x,y);
		cout << "|";	
		vt100gotoxy(x,y);
		cout << "\\";	
		}
	vt100gotoxy(x,y);
	c=7;
	vt100setcolor(c);
	cout << "O";	
	}

void vt100clear() {
	cout << ESC << "[2J" << ESC << "[f";
	}

void vt100gotoxy(int x, int y) {
	cout << ESC << "[" << y << ";" << x << "H";
	}

void vt100setcolor(int c) {
	cout << ESC << "[3" << c << "m";
	}

void vt100setbackground(int c) {
	cout << ESC << "[4" << c << "m";
	}
Last edited on
Topic archived. No new replies allowed.