Table of content

Previous: 7.c Building moving spheres

Lesson 8. Putting it all together: the BIG one

   
   

Figure 8.1: Snapshot of the effect in level8.wed at 4 consecutive instants (from top-left to bottom-right). Red leaders are first created and sent in every direction with a high velocity; they then quickly slow down. A while after their creation, they become bright red and start leaving white trails behind before disappearing. The tail particles become dark blue as they age to add structure to the effect.

We now come to the last lesson of this tutorial where we bring together spherical coordinates and the formulas of lesson 4 for particle trails, to obtain the result shown on Figure 8.1. Though pretty in its own right (this is a particle effect rendition of a classic fireworks effect called a 'chrysanthemum'), it can be generalized in principles to any mid- air explosion. Indeed, the algorithm presented here consists in emitting leaders in all directions of space, which then leave behind them particle trails. For the chrysanthemum, the leaders are red rockets with propellers emitting blue-ish sparks. For an ordinary explosion, the leaders could be debris leaving behind plumes of smoke or flames.

a. The big one

The script is actually very similar to that presented in lesson4 for the roman candle. There is an action, a_chrysanthemum, which we attach to an invisible entity and which fires leaders along any outward direction. The leaders carry the, well, the function leader(), and they emit trail particles with function tail() attached to them. We will look at all three of them in turn, emphasizing tricks special to this script.

First, the action for the entity which produces the leaders:

var initial_velocity = 70; 
var spacing = 0.25;

action a_chrysanthemum
{	
	my.invisible = on;
	my.skill1 = 0;			
	var velocity;
	var phi;
	var theta;
	var dphi;
	var dtheta;
	var nb_theta;
	var nb_phi;
	
	while(1)
	{
		if ((key_1==1) & (my.skill1==0))
		{
			// initialize delay
			my.skill1 = 16;		// delay to prevent multiple firing 
			
			// we create a group of spherically distributed leaders
			phi = 0;		
			theta = 0;	
			nb_theta = pi/spacing;
			dtheta = 180/nb_theta;	
			
			while(theta<=180)
			{
				nb_phi = 2*pi*sin(theta)/spacing;
				if (nb_phi!=0)
				{
					dphi = 360/nb_phi;
				}
				else
				{
					dphi = 360;
				}
				
				phi = 0;
				while(phi<360)
				{
					velocity.x = initial_velocity*cos(phi)*sin(theta);
					velocity.y = initial_velocity*sin(phi)*sin(theta);
					velocity.z = initial_velocity*cos(theta);
					effect(leader,1,my.pos,velocity);
					phi += dphi;
				}
				theta += dtheta;	
			}
		}
		
		// updating of the timer
		if (my.skill1>0)
		{
			my.skill1 -= time;
		}
		else
		{
			my.skill1 = 0;
		}
		wait(1);
	}
}

There are two parts in the action: one which implements a delay of at least 16 ticks between explosions, and the other which chooses the initial velocities of the leaders and creates them. We recognize the loops on theta and phi we already saw in lesson 7. However, things seem to be a little more complicated than before: instead of increasing angles theta and phi in constant steps of 10 degrees like in lesson7.wdl, we increase them by dtheta and dphi which seem to depend on the angle theta. Why is that?

Next: 8.b Spherical distribution of leaders