# Firework: Circle with cosine & sine but in 3D....?

Hello all,

I made a fire work in 2D (its movement is 2D anyway) with a simple formula using cos and sin.

``````  void move() {

// Spark move

// move

}// function
``````

My question is, how can I make it so that the movement would be 3D (sparks fly away forming a full sphere)

``````  void move() {

// Spark move

// move

}// function
``````

(full 2D movement sketch Some Movies I made )

Thanks all!

Chrisir

One way is to rotateY before translating x,y – so different circles of sparks will fly in different directions. This won’t look like a sphere, though, more like a beachball.

Another option is to plot the point on a sphere, then scale it as it flies out. Multiple methods of doing that – one by you (!)…

1 Like

Hello @Chrisir,

This was just me tinkering with formulas.
There may be something useful in this for you; I know I will play with this some more!
Thanks for inspiring me.

``````void draw()
{
translate(width/2, height/2);
rotateX(TAU/4);

for(float angle = 0; angle < TAU; angle += TAU/100)
{
strokeWeight(3);
stroke(255, 255, 0);
point(x, y, z);
}

t += .1;
}

void move(float angle, float t, float radius)
{
z = 100*(1-pow(exp(1.0), 1-t/5));

//t += .1;
}
``````

2 Likes
``````float t, radius;
float x, y, z;

float speed= 44;

void setup() {
size(1900, 900, P3D);
background(0);
y=height-533;
}

void draw() {
// background(0);
translate(width/2, height/2);
// rotateX(TAU/4);

for (float angle = 0; angle < TAU; angle += TAU/speed) {
strokeWeight(3);
stroke(255, 255, 0);
point(x, y, z);
}

t += .1;

speed+=1;
if (speed>100)
speed=100;
}

void move(float angle, float t, float radius) {

// y = 4- 100*(1-pow(exp(1.0), 1-t/5));
//t += .1;
}
``````
2 Likes

I like it!

I had the formula for capacitors charging on my mind and did not want the fireworks to end. 1 Like

Thanks again!

3 Likes