PDA

View Full Version : [Chaoswarp Entry 1] - Box Fitting


Chaoswarp
01-18-2006, 12:52 PM
Title:
Fractal Box Fitting

Steps:
Given any rectangular area, place a reactange inside, divide the remaining space into 8 new areas, loop until area is too small.

Interaction:
Color Change when you wiggle your mouse (on a 2 second timer)
Click to reset the whole thing.

Code:

function drawRect(mc:MovieClip) {
mc.beginFill(vars_obj.color, (Math.floor(Math.abs(mc.x2-mc.x)*Math.abs(mc.y2-mc.y))/(vars_obj.minSize*30+10))*100);
//1
mc.moveTo(mc.x, mc.y);
//2
for (var i in mc.coords_array) {
//3
mc.lineTo(mc.coords_array[i][0], mc.coords_array[i][1]);
//4
}
mc.endFill();
//5
var myTween = new mx.transitions.Tween(mc, "_y", mx.transitions.easing.Elastic.easeOut, -100, 0, (Math.round(Math.random()*0)+.4), true);
//6
}
function makeRegion(x, y, x2, y2) {
if (((x2-x)>vars_obj.minSize) && ((y2-y)>vars_obj.minSize)) vars_obj.queue.push({x:x, y:y, x2:x2, y2:y2});
//7
}
function recursive(obj) {
var mc = vars_obj.holder.createEmptyMovieClip("region"+obj.x+":"+obj.y, vars_obj.holder.getNextHighestDepth());
//8
mc.x = (Math.random()*((obj.x2-vars_obj.minSize)-obj.x))+obj.x;
//9
mc.x2 = (Math.random()*((mc.x+vars_obj.minSize)-(obj.x2)))+(obj.x2);
//10
mc.y = (Math.random()*((obj.y2-vars_obj.minSize)-obj.y))+obj.y;
//11
mc.y2 = (Math.random()*((obj.y2)-(mc.y+vars_obj.minSize)))+(mc.y+vars_obj.minSize);
//12
mc.coords_array = [[mc.x2, mc.y], [mc.x2, mc.y2], [mc.x, mc.y2], [mc.x, mc.y]];
//13
var region_array = [[obj.x, obj.y, mc.x, mc.y], [mc.x, obj.y, mc.x2, mc.y], [mc.x2, obj.y, obj.x2, mc.y], [obj.x, mc.y, mc.x, mc.y2], [mc.x2, mc.y, obj.x2, mc.y2], [obj.x, mc.y2, mc.x, obj.y2], [mc.x, mc.y2, mc.x2, obj.y2], [mc.x2, mc.y2, obj.x2, obj.y2]];
//14
for (var i in region_array) {
//15
makeRegion(region_array[i][0], region_array[i][1], region_array[i][2], region_array[i][3]);
//16
}
drawRect(mc);
//17
}
_root.onEnterFrame = function() {
vars_obj.queue.length>0 ? recursive(vars_obj.queue.pop()) : null;
//18
};
_root.onMouseMove = function() {
if (vars_obj.colorTimer == null) {
//19
vars_obj.colorTimer = true;
//20
vars_obj.color = (Math.random()*0xffffff);
//21
setTimeout(function () {vars_obj.colorTimer = null;}, 2*1000);
//22
}
};
_root.onMouseUp = init=function () {
vars_obj = {minSize:8, color:(Math.random()*0xffffff), queue:new Array(), holder:_root.createEmptyMovieClip("holder", 1)};
//23
makeRegion(0, 0, Stage.width, Stage.height);
//24
};
init();
//25


Hope you all like it :)

nobody
01-18-2006, 12:54 PM
Put your entry in the right tags for ya :)

Looks great, good work.

squan
01-18-2006, 12:56 PM
That's pretty neat :) I like the effect.

freeskier89
01-18-2006, 06:42 PM
Is the tween class as used above allowed?

bombsledder
01-18-2006, 06:42 PM
arent you not aloud any imports?

var myTween = new mx.transitions.Tween(mc, "_y", mx.transitions.easing.Elastic.easeOut, -100, 0, (Math.round(Math.random()*0)+.4), true);

or am i wrong?

ElectricGrandpa
01-18-2006, 07:36 PM
arent you not aloud any imports?

var myTween = new mx.transitions.Tween(mc, "_y", mx.transitions.easing.Elastic.easeOut, -100, 0, (Math.round(Math.random()*0)+.4), true);

or am i wrong?

The Tween class(as used here) is *legal*, as it has not been called using an import statement. The main purpose of the import rule is to ensure that people don't import custom classes, it's not to limit Flash 8 users.

Oh, and I absolutely love box fitting! Nice work!

Sweet, 1000th post!

hybrid101
01-19-2006, 05:38 AM
nice! i like the dropping rectangles forming cool patterns!

treatkor
01-19-2006, 07:11 AM
this is so neat. reminds me of some of the generative artworks on levitated.net
you could do a nice image mask effect with this.

Chaoswarp
01-19-2006, 11:21 AM
Thanks! :) Except for bombsledder and freeskier89 you guys are evil... :angry:
hehe just messing...

treatkor:
Good call, I am a big Jared Tarbell fan, and box fitting came from studying one of his open source experiments (http://www.levitated.net/daily/levBoxFitting.html) about a year ago or so.

I love the fact people are out there creating code based art, and I love making it.

Thanks again guys :)

NiñoScript
01-19-2006, 02:44 PM
wow! really cool!! :!:

i love fractals :P

Seb Hughes
01-19-2006, 03:52 PM
Wow thats insane, i like it.

Gelatine Cow
01-19-2006, 10:46 PM
Very nice :thumb2:

TheCanadian
01-19-2006, 11:32 PM
The main purpose of the import rule is to ensure that people don't import custom classes, it's not to limit Flash 8 users.
That doesn't prevent people from using their their own classes. import is used so you don't need to type in the qualified class path every time you want to use a class not included at the global path or in the same directory as your FLA - it has no affect on the movie whatsoever except for the fact that the author doesn't need to type as much. I still feel that using the BitmapData, filter, etc classes is a disadvantage for people with MX04 or lower but if nobody else is bothered by it then I guess I won't be either :tie:

Great work :beer:

ElectricGrandpa
01-19-2006, 11:43 PM
Yeah I dunno what I was talking about when I posted... as I know that you don't need imports to get custom classes... So, um, yeah. Bah.

I still feel that using the BitmapData, filter, etc classes is a disadvantage for people with MX04 or lower but if nobody else is bothered by it then I guess I won't be either

I'd like to think of it more as just something extra for people with Flash 8, rather than a real "advantage". In the end we all still have 25 lines to work with, and all the best entries I've seen so far haven't used any extra classes(well, except this one, but it's just tweening which could easily be done in mx04 as well).

-Matt

Krilnon
01-20-2006, 07:19 AM
I see no reason not to allow people to use Flash 8 features. Some people still use Flash MX and make things that I couldn't make with Flash 8. I think the judges will be judging on talent rather than what version of Flash people are using.

Sinister Shadow
01-20-2006, 04:37 PM
That looks very funky!

Well, what exactly does dissallowing the import statement achieve?

ElectricGrandpa
01-20-2006, 06:50 PM
Well, what exactly does dissallowing the import statement achieve?

Not sure exactly, but it keeps people from accidently wasting a line by using it :D

Chaoswarp
01-23-2006, 01:39 PM
I am just playing the game by the rules that have been set up :)

To quote Kirupa from the guidelines:

"You can use built-in classes, but you can't use 3rd party classes. If any classes come pre-installed with Flash, you can do whatever you want with them :)"

and

" As long as there are 25 lines of code and an SWF, I don't think it matters which version of Flash you write your code in."

The contest is to come up with the best way to use 25 in line in whatever tool's you have available. If you don't have flash 8 I guess you could view that as a disadvantage, but I would say, like in any competition, the tools you use can be a advantage in the game. I am sure the judges will be looking for coding quality not who used a cool motion tween class. The tween was just added to make the project look less boring.

If you were to remove the one line that uses a built in class the main premise of the project wouldnt change at all.

But by the rules of this game all 25 lines could reference a built in class and be perfectly legal in the game.

:) thats what I think anyways and thats why I think built in classes are allowed.

Dont mean to start anything, just playing by the rules.

SimplyArun
02-06-2006, 02:47 AM
pretty good!

birenpatel
03-03-2006, 12:25 PM
Great Effect.

Is it possible to use this effect to mask a PICTURE?

vega
07-14-2006, 07:55 AM
Very nice.

I love the small touches- changing the colours with mousemove etc. Makes it a bit more ..dynamic.