PDA

View Full Version : Spiral Fractal



jerez_z
January 27th, 2006, 05:50 PM
This is my Spiral Fractal V1 & V2. They are both 25 lines. I wouldsn't recommend having more than two going at any time. Click anywhere to start a new one. My original inspiration: linky (http://www.deviantart.com/deviation/23206638/)

V1:

Stage.scaleMode = "noScale";
MovieClip.prototype.randPos = function(click) {
this._x = (click) ? _root._xmouse : Math.random()*400+75;
this._y = (click) ? _root._ymouse : Math.random()*300+50;
};
MovieClip.prototype.putOnParent = function(clip) {
this._x = clip.stuff.current.x+clip._x;
this._y = clip.stuff.current.y+clip._y;
};
MovieClip.prototype.draw = function() {
(mat=new flash.geom.Matrix()).translate(this._x, this._y);
all.draw(this, mat);
this.clear();
};
_root.attachBitmap((all=new flash.display.BitmapData(550, 400)), 1);
function genBranch(clip, onBranch, level, click, numKids) {
(onBranch) ? col=clip.stuff.c : col=(0x638A00*((randCol=Math.random())>.5))+(0xBDEB00*(randCol<=.5));
(c=_root.createEmptyMovieClip("branch"+_root.getNextHighestDepth(), _root.getNextHighestDepth())).stuff = {l:level, av:0, a:(onBranch) ? clip.stuff.a+(Math.random()*90-45)*(Math.random()>.2) : Math.random()*360, c:col, aav:(Math.random()-.5)/2, t:(clip.stuff.t != undefined) ? clip.stuff.t : 5, current:new flash.geom.Point(), child:0, lastChild:0, age:0, currentg:(clip.stuff.currentg == undefined) ? new flash.geom.Point() : clip.stuff.currentg};
(onBranch) ? c.putOnParent(clip) : c.randPos(click);
c.onEnterFrame = function() {
this.lineStyle(this.stuff.t, this.stuff.c, 100);
this.stuff.av += this.stuff.aav;
this.stuff.a += this.stuff.av;
this.moveTo(this.stuff.current.x, this.stuff.current.y);
(this.stuff.current=new flash.geom.Point(this.stuff.current.x+Math.cos(thi s.stuff.a*Math.PI/180)*5, this.stuff.current.y+Math.sin(this.stuff.a*Math.PI/180)*-5));
this.lineTo(this.stuff.current.x, this.stuff.current.y);
this.localToGlobal((this.stuff.currentg=this.stuff .current.clone()));
(((this.stuff.currentg.x>450 || this.stuff.currentg.x<100 || this.stuff.currentg.y>350 || this.stuff.currentg.y<50) || Math.random()*100>80) && this.stuff.child<5-this.stuff.l && this.stuff.lastChild>this.stuff.age-300 && (this.stuff.lastChild>0 || this.stuff.age>30)) ? genBranch(this, true, this.stuff.l+1, (this.stuff.child++)) : this.stuff.age++;
this.draw();
((this.stuff.currentg.x>600 || this.stuff.currentg.x<-100 || this.stuff.currentg.y>500 || this.stuff.currentg.y<-100 || this.stuff.t<.1) && this.stuff.age>60) ? this.removeMovieClip() : this.stuff.t *= 1-(this.stuff.l/300);
};
}
onMouseDown = function () {
genBranch(_root, false, 1, true);
};
genBranch(_root, false, 1, false);
genBranch(_root, false, 1, false);


V2:

Stage.scaleMode = "noScale";
MovieClip.prototype.randPos = function(click) {
this._x = (click) ? _root._xmouse : Math.random()*400+75;
this._y = (click) ? _root._ymouse : Math.random()*300+50;
};
MovieClip.prototype.putOnParent = function(clip) {
this._x = clip.stuff.current.x+clip._x;
this._y = clip.stuff.current.y+clip._y;
};
MovieClip.prototype.draw = function() {
(mat=new flash.geom.Matrix()).translate(this._x, this._y);
all.draw(this, mat);
this.clear();
};
_root.attachBitmap((all=new flash.display.BitmapData(550, 400)), 1);
function genBranch(clip, onBranch, level, click, numKids) {
(onBranch) ? col=clip.stuff.c : col=(0x638A00*((randCol=Math.random())>.5))+(0xBDEB00*(randCol<=.5));
(c=_root.createEmptyMovieClip("branch"+_root.getNextHighestDepth(), _root.getNextHighestDepth())).stuff = {l:level, av:0, a:(onBranch) ? clip.stuff.a+(Math.random()*90-45)*(Math.random()>.2) : Math.random()*360, c:col, aav:(Math.random()-.5)/3, t:(clip.stuff.t != undefined) ? clip.stuff.t : 5, current:new flash.geom.Point(), child:0, lastChild:0, age:0, currentg:(clip.stuff.currentg == undefined) ? new flash.geom.Point() : clip.stuff.currentg};
(onBranch) ? c.putOnParent(clip) : c.randPos(click);
c.onEnterFrame = function() {
this.lineStyle(this.stuff.t, this.stuff.c, 100);
(Math.abs(this.stuff.av)>60) ? this.kill() : this.stuff.av += (this.stuff.aav += (Math.random()/10)*((-1*(this.stuff.aav<0))+((1*(this.stuff.aav>0)))));
this.stuff.a += this.stuff.av;
this.moveTo(this.stuff.current.x, this.stuff.current.y);
(this.stuff.current=new flash.geom.Point(this.stuff.current.x+Math.cos(thi s.stuff.a*Math.PI/180)*5, this.stuff.current.y+Math.sin(this.stuff.a*Math.PI/180)*-5));
this.lineTo(this.stuff.current.x, this.stuff.current.y);
this.localToGlobal((this.stuff.currentg=this.stuff .current.clone()));
(((this.stuff.currentg.x>450 || this.stuff.currentg.x<100 || this.stuff.currentg.y>350 || this.stuff.currentg.y<50) || Math.random()*100>80) && this.stuff.child<5-this.stuff.l && this.stuff.lastChild>this.stuff.age-300 && (this.stuff.lastChild>0 || this.stuff.age>30)) ? genBranch(this, true, this.stuff.l+1, (this.stuff.child++)) : this.stuff.age++;
this.draw();
((this.stuff.currentg.x>600 || this.stuff.currentg.x<-100 || this.stuff.currentg.y>500 || this.stuff.currentg.y<-100 || this.stuff.t<.1) && this.stuff.age>60) ? this.removeMovieClip() : this.stuff.t *= 1-(this.stuff.l/300);
};
}
onMouseDown = function () {
genBranch(_root, false, 1, true, 0);
};
genBranch(_root, false, 1, false, 0);
genBranch(_root, false, 1, false, 0);


EDIT: adjusted how fast the lines lose thickness

TheCanadian
January 27th, 2006, 06:00 PM
Wow - great job :king:

freeskier89
January 27th, 2006, 06:00 PM
That is way too good jeremy :D

jerez_z
January 27th, 2006, 06:02 PM
alright edited slightly after comments from freskier

watcher
January 29th, 2006, 08:55 AM
i 'love' fractals..

But does anybody know, why - when i compile this code in Flash - the output SWF doesn't work, neither does the one uploaded on this site from my HDD?

It works in browser though..

But what you've done i like so much Jeremy. Cheers! :)

applejelly
January 29th, 2006, 09:38 AM
great stuff :thumb:

McGiver
January 29th, 2006, 10:13 AM
I love fraktals :love:
make more make more :)

Gelatine Cow
January 30th, 2006, 08:00 AM
That's great!

And the clicking to draw more spirals: :love:

hybrid101
January 31st, 2006, 06:06 AM
v2 looks awesome! i love this entry!

pom
January 31st, 2006, 02:11 PM
Very nice. So nice that it looks great even tough it's green :stunned:

jerez_z
January 31st, 2006, 02:12 PM
the colors from the inspiration went so good together I figured I'd keep em togehter

Seb Hughes
January 31st, 2006, 04:54 PM
Really Nice Jeremy.

kdd
January 31st, 2006, 09:32 PM
wow, these are cool!

virusescu
February 2nd, 2006, 05:25 PM
Very very nice fractal job. Awesome:thumb:

SimplyArun
February 6th, 2006, 03:43 AM
Lovely stuff! :thumb2:

BetaWar
February 22nd, 2007, 12:04 AM
Holy cow, I may be new here, but that is awesome.

I love fractals, just wish I could make any that were this cool!