Put some Java to your next Valentine’s Day

As I told you in my description, I like waste my time to code just for fun… But don’t misunderstand me, it could be fun, but also enlightening in many ways.

When I began to communicate in machine-languages ( I mean to code lol), of course as every child I want to make a video-game ! After some tries, I conclude that what I prefer is to code graphics effects.

One of my favourite effect is the simple fireworks effect ! As my title suggests, I will give you some codes and explanations to help you design (big word!) a beautiful fireworks effect to make falling down the heart of your girlfriend (depending on her… 😉 ).

So now, let’s put some Java into your love !

By my way, we could break up the fireworks in three effects:

the movement effect (bomb movement, explosion movement)

the fire effect

(surprise)

In this first code post, I will explain the movement effect, all in Java.

If you want to learn Java, without the boring “Hello World !”, this is a good start ! The code is simple not difficult.

The movement equation

We have to “create” an equation which could simulate a throw. This is the mysterious part for anyone of you who totally forgot the famous functions: sines and cosines !

this.x_initial and this.y_initial, are the initial coordinates of the ball

this.v_initial means initial velocity of the ball, but in fact it’s just the amplitude of my sin or cos functions, more this value is high, faster will be the rise and the descent of the ball (to figure it out simply)

this.theta is the start angle of your throw

this.a_initial is the acceleration.

finally, this.t it’s the time parameter (iterator).

To figure out how it works, it’s very simply, we could imagine the circle of trigonometry, and all we have to do, is to find a way to distort the circle on the ellipse, which match with the form we want for our throw:

distort the sin and cos functions to find the right throw to our ball

Try to modify some parameters, and find your own ellipse ! You could also try to find a new trajectory for your ball, for example, you could find something which similar to a flight of fairy !

Mathematical explanations

Ok if you want a full explanations, it’s not a good place, check these links (because I’m not a good physicians, and latex users too ! 😉 ):