Seb Lee-Delisle


Animated Plasma in Flash

OK you can tell I’m fired up right now. I should be going to sleep but instead I’m blogging about a cool plasma effect I just programmed.

Most of you won’t know that my programming career started on the Commodore Amiga. And my mentor was one of the leading demo coders, Jolyon Ralph. So, for old times’ sake, here is an actual plasma effect, programmed in Flash.

It's actually quite simple... we're just calculating the colour for each pixel using the following code :

	v = Math.sin(dist(x + time, y, 128.0, 128.0) / 8.0)
		+ Math.sin(dist(x, y, 64.0, 64.0) / 8.0)
		+ Math.sin(dist(x, y  , 192.0, 64) / 7.0)
		+ Math.sin(dist(x, y+ time/ 7, 192.0, 100.0) / 8.0);
	colour = int((4 + v)) * 32;

where x and y are the positions of the pixel, t is a value for time, incrementing by 1 every frame. The sin function is the Math.sin function, and dist is a function that calculates distance between two points:

function dist(a:Number, b:Number, c:Number, d:Number)
	return Math.sqrt(((a - c) * (a - c) + (b - d) * (b - d)))

Pretty cool that Flash is finally catching up with the computing power of the Amiga! Hmmm.

Thanks to Lode Vandevenne for the refresher course...

This entry was posted in Actionscript, Flash, Flash Physics, Obsolete. Bookmark the permalink.

14 Responses to Animated Plasma in Flash