Created
October 21, 2012 11:30
-
-
Save Fintan/3926739 to your computer and use it in GitHub Desktop.
Plasma (Seb Lee's)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
see it working here: http://try.haxe.org/#Bb6eF | |
taken from here: http://seb.ly/2007/11/animated-plasma-in-flash/ | |
*/ | |
import flash.display.BitmapData; | |
import flash.events.Event; | |
import flash.display.Bitmap; | |
class Test { | |
var bitmapData:BitmapData; | |
var width:Int; | |
var height:Int; | |
var v:Float; | |
var colour:Int; | |
var time:Float; | |
public function new() { | |
width = 200; | |
height = 150; | |
time = 0; | |
var bitmap = new Bitmap(); | |
bitmapData = new BitmapData( width, height, false , 0x000000 ); | |
bitmap.bitmapData = bitmapData; | |
flash.Lib.current.addChild( bitmap ); | |
flash.Lib.current.addEventListener(Event.ENTER_FRAME, enterFrame); | |
} | |
function enterFrame(e) { | |
for(ix in 0...width) { | |
for(iy in 0...height) { | |
v = Math.sin(dist(ix + time, iy, 128.0, 128.0) / 8.0) | |
+ Math.sin(dist(ix, iy, 64.0, 64.0) / 8.0) | |
+ Math.sin(dist(ix, iy , 192.0, 64) / 7.0) | |
+ Math.sin(dist(ix, iy+ time/ 7, 192.0, 100.0) / 8.0); | |
colour = Std.int((4 + v)) * 32; | |
bitmapData.setPixel(ix, iy, colour); | |
} | |
} | |
time += 1.5; | |
} | |
inline function dist(a:Float, b:Float, c:Float, d:Float) | |
{ | |
return Math.sqrt(((a - c) * (a - c) + (b - d) * (b - d))); | |
} | |
static function main() { | |
new Test(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment