This is a blog about Flash & AS by betaruce :-)



Calendar

August 2007
M T W T F S S
« Jul    
  1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31  

October 26, 2005

AS 3 Experiment: Animated Plasma (speed improvement)

Filed under: My Flash Programs — betaruce @ 1:20 pm

Compared with my same experiment produced in Flash 8, the following (you will need Flash Player 8.5 to see it) is much faster and smoother since it is coded with AS 3.

http://www.box-hosting.net/~betaruce/as3/plasma.swf

This animated plasma effect is created with pixel manipulation. In my Flash 8 version, there are 120*120=14400 calculations/frame and of cause it hangs Flash player 8. In the above example, there are 300*300=90000 calculations/frame and the speed is awesome in player 8.5. On my 1.5Ghz computer the speed is still satistfactory for 500*500=250000 calculations/frame.

The following is the code:


package {
import flash.display.*;
import flash.geom.*;
import flash.util.*;
import flash.events.*;

public var sx:int;
public var sy:int;
public var pixels:Array=new Array();
public var palette:BitmapData;
public var b:BitmapData;
public var bm:Bitmap;

public class plasma extends MovieClip {
public function plasma() {
stage.align=’TOP_LEFT’;
stage.scaleMode=StageScaleMode.SHOW_ALL;
sx=stage.stageWidth;
sy=stage.stageHeight;
//
var colors:Array=[0xff0000,0xffff00,0×00ff00,0×00ffff,0×0000ff,0xff00ff,0xff0000];
var alphas:Array=[100,100,100,100,100,100,100];
var ratios:Array=[0,43,85,128,170,212,255];
var mat:Matrix=new Matrix();
mat.createGradientBox(256,1);
var gradient:MovieClip=new MovieClip();
gradient.graphics.beginGradientFill(’linear’,colors,alphas,ratios,mat);
gradient.graphics.drawRect(0,0,256,1);
//
palette=new BitmapData(256,1,false);
palette.draw(gradient,new Matrix());
b=new BitmapData(sx,sy,false);
bm=new Bitmap(b);
addChild(bm);
//
var den:int=16;
for(var i:int=0;i
var temp:Array=new Array();
for(var j:int=0;j
temp[j] = 128+128*Math.sin(i/(den*2));
temp[j] += 128+128*Math.sin(j/(den*4));
temp[j] += 128+(128*Math.sin(Math.sqrt((i-sx/2)*(i-sx/2)+(j-sy/2)*(j-sy/2))/den));
temp[j] += 128+128*Math.sin(Math.sqrt(i*i+j*j)/den);
temp[j] /= 4;
}
pixels.push(temp);
}
addEventListener(EventType.ENTER_FRAME,onEnterFrame);
}

private function onEnterFrame(e:Event){
for (var i:int=0; i
for (var j:int=0; j
var temp:Number = getTimer()/20;
b.setPixel(i, j, palette.getPixel(int((pixels[i][j]+temp)%256), 0));
}
}
}
}
}

• • •

5 Comments »

  1. […] ��Almost!?!?!? Security??? AS 3 Experiment: Bouncing balls Betaruce (source and example) AS 3 Experiment: Animated Plasma Betaruce (source and example) AS 3 Experiment: Asteroids Ro […]

    Pingback by Franto.com Flash blog » Collected links to ActionScript 3.0 examples — October 26, 2005 @ 4:59 pm
  2. Sorry but your swf link is broken…annoying.

    Comment by ehh — June 30, 2006 @ 6:45 pm
  3. […] AS 3 Animated Plasma plasma effect as3 (tags: plasma effect as3) […]

    Pingback by d3 blog » Blog Archive » links for 2006-07-12 — July 13, 2006 @ 1:04 am
  4. Your blog system is eating your code when you submit it, I think. Especially loops! Also, no swf examples.

    Comment by Alec — February 4, 2007 @ 8:03 am
  5. it’s not very good without SWFs :(

    my kids dirt bikes page

    Comment by yEblog — March 24, 2007 @ 8:05 pm

Comments RSS • TrackBack URI

Leave a comment

Powered by: WordPress • Template by: Priss

cheap phentermine phentermine site phentermine effects online phentermine phentermine prescription buy phentermine online phentermine alternatives phentermine deit pill cheap generic phentermine order phentermine online Clenbuterol Phentermine online pharmacy phentermine buy phentermine weight loss pill Cialis Comparison Viagra Cheap Viagra Online Prescription generic viagra sale viagra online viagra viagra pill discount sale viagra Generico Impotencia Viagra viagra sildenafil citrate Xanax Online xanax order xanax valium versus xanax