Skip to content
← Back to Community
Making Fireworks in c++ using basic code
Profile icon
azula21

Hello! If anyone can explain me the logic of creating basic fireworks in C++. I have to make the firework swirl though. If someone can guide me what header files to use, and a bit of the logic, it would be a great help!

Voters
Profile icon
Fletchman1
Profile icon
azula21
Comments
hotnewtop
Profile icon
xxpertHacker

btw, if you're taking that array approach, you'll probably want to be using raw strings instead of "normal" strings:

It'll make your life a bit easier.

Profile icon
badst

opengl?

Profile icon
azula21

@pepelaugh uhhh! no, I can not use that, sadly
edit: using ascii values.

Profile icon
badst

@azula21 use graphics.h then
edit: if you need to use ascii you would need to have the x position and y position of the firework and calculate the next position (assuming it's animated and you want it to "explode")

Profile icon
azula21

@pepelaugh can't use that either dude. That is the main issue. Do you know any way which I can use to make my firework look like its going from the bottom to the top?

Profile icon
badst

@azula21 Like the swirls going up or just the ascii art itself moving up?(so is the ascii art being actively affected eg, it grows larger, spreads out, etc... or do you just want a still firework ascii piece moving up the screen)

Profile icon
azula21

@pepelaugh swirls growing larger would be even great, an ascii piece going up would be enough too..
Thankyou in advance!

Profile icon
badst

@azula21 simplest possible way is to have a folder of files which contain frames of fireworks, and for each frame, clear the terminal and cout the next file to the terminal.

if you want it to be generated, i'd say you'd have to calculate the vector between the edge of the screen and the center of the firework, and increase the edge of the firework by the vector.

Profile icon
azula21

@pepelaugh It may seem weird but I can't use vector eithers, actually only arrays, loops, ascii and basic stuff for that.
However, thanks a lot for the contribution.

Profile icon
badst

@azula21 Ah- then the first answer would work for you, would it not? If you do not want to use files, you could store each frame in an array and loop through it, clearing the terminal at each frame. This would simulate a animation.

Profile icon
xxpertHacker

@azula21 Is this a school assignment or what?
How experienced are you with C++?

Profile icon
azula21

@xxpertHacker, im good with basics, loops arrays and stuff, and yes its an assignment!

Profile icon
CSharpIsGud

@azula21 Just use fixed size arrays, you don't need vectors or anything

Profile icon
azula21

@CSharpIsGud any idea how can I print those so that it looks it goes from the bottom to the top?

Profile icon
badst

@xxpertHacker @CSharpIsGud @azula21 Here, use this as a start:

#include <iostream> #include <array> int main() { std::array<std::string,4> frames = { "Frame1", "Frame2", "Frame3", "Frame4" }; for(auto & frame : frames){ std::cout << frame; } }

Replace "Frame1","Frame2",etc with animation frames.
Then add a sleep function and clear the console.

Profile icon
azula21

@pepelaugh Thanks alot! I'll try that!

Profile icon
xxpertHacker

@pepelaugh A sleep function would require threading, would it not? Or maybe there's a simple blocking way to cause a delay?

Profile icon
badst

@xxpertHacker mhm. i use thread for sleep. if op is on windows he can use Sleep

Profile icon
xxpertHacker

@pepelaugh Well, if they can't use "advanced" stuff, and if it's for a school assignment, they might not be able to use... either.

All depends on the teacher/course though.

Profile icon
badst

@xxpertHacker yeah, the school wants them to disable the cpu for sleep, lmao.

To be honest, I doubt any school will restrict "advanced" code, that's just weird.

Profile icon
xxpertHacker

@pepelaugh Thankfully my teachers never said "no, you haven't learned that, so you're not allowed to use it", but I've heard of plenty doing just that.