Hello, I’m trying to make a plasma fractal (as a self-challenge, I made the sierpinski triangle,
Koch snowflake, Mandelbrot set, Julia set, and dragon fractal. If you want the code,
PM/reply.)
Here’s the code of frame 1:
//PLASMA FRACTAL
Square.c = 256/400;
var t:Array = new Array(new Square(new Point(0,0),new Point(400,400),Math.random()*256,Math.random()*256,Math.random()*256,Math.random()*256));
function doIt(...args) {
graphics.clear();
var temp:Array = new Array();
for (var i:int = 0; i < t.length; i++) {
var tri:Square = t* as Square;
temp=temp.concat(tri.subdivide());
}
t=temp;
for (var o:int = 0; o < t.length; o++) {
var tr:Square = t[o] as Square;
tr.draw(graphics);
}
}
btn.addEventListener(MouseEvent.CLICK,doIt);
graphics.clear();
t[0].draw(graphics);
/**/ //These are for easy commenting out. I put all the fractals in one place.
Square subdivide:
public function subdivide():Array {
var h:uint = (h1+h2+h3+h4)/4+Math.random()*(s.x*c);
var r1:Square = new Square(o.clone(),new Point(s.x/2,s.y/2),h1,(h1+h2)/2,(h1+h3)/2,h);
var r2:Square = new Square(o.clone(),new Point(s.x/2,s.y/2),(h1+h2)/2,h2,h,(h2+h4)/2);
var r3:Square = new Square(o.clone(),new Point(s.x/2,s.y/2),(h1+h3)/2,h,h3,(h3+h4)/2);
var r4:Square = new Square(o.clone(),new Point(s.x/2,s.y/2),h,(h2+h4)/2,(h3+h4)/2,h4);
r2.o.offset(s.x/2,0);
r3.o.offset(0,s.y/2);
r4.o.offset(s.x/2,s.y/2);
var a:Array = new Array(r1,r2,r3,r4);
return a;
}
It’s making these weird square shaped things. Run it and see.
constructor/variables:
public var o:Point;
public var s:Point;
public var h1:uint,h2:uint,h3:uint,h4:uint;
public static var c:Number = 0;
public function Square(st:Point=null,sz:Point=null,htl:uint=0,htr:uint=0,hbl:uint=0,hbr:uint=0) {
if (st == null) {
st=new Point();
}
if (sz == null) {
sz=new Point();
}
o=st;
s=sz;
h1=htl;
h2=htr;
h3=hbl;
h4=hbr;
}