Fun with the MX drawing API

I just got a new book called “Fresh Flash” it’s made by the same people that did “Flash Math Creativity” both are great books. I did the first tutorial in the book and for once I actually understand everything I just typed in from the book. If any of you have the opportunity check the books out on the www.friendsofed.com website or buy them … they’re great. Here’s the code from the first exercise I did. See if you can understand it too (statement not directed at all the gurus that we know would understand it).

just copy and paste this code onto your frame’s actionscript


onMouseDown = init;
function init() {
r1 = Math.random()*128;
g1 = Math.random()*128;
b1 = Math.random()*128;
r2 = Math.random()*128+127;
g2 = Math.random()*128+127;
b2 = Math.random()*128+127;
rinc = (r2-r1)/40;
ginc = (g2-g1)/40;
binc = (b2-b1)/40;
ampX = Math.random()*20+5;
wavelengthX = Math.random();
ampX1 = Math.random()*10;
wavelengthX1 = Math.random();
ampY = Math.random()*10;
wavelengthY = Math.random();
clipDepth = 0;
_root.onEnterFrame = drawShape;
}
function drawShape() {
	clip_mc = createEmptyMovieClip("clip"+clipDepth, 1000-clipDepth++);
	clipY = 400-clipDepth*10;
	if (clipY<=0) {
		delete _root.onEnterFrame;
	}
	clip_mc._y = clipY;
	clip_mc.lineStyle(1, 0x000000, 20);
	shapeCol = r1 << 16 | g1 << 8 | b1;
	clip_mc.beginFill(shapeCol, 100);
	angleX = Math.sin(angleY += wavelengthY)*ampY;
	for (i=0; i<56; i++) {
		x = i*10;
		y = Math.sin(angleX += wavelengthX)*ampX+Math.sin(angleX1 += wavelengthX1)*ampX1;
		clip_mc.lineTo(x, y);
	}
	clip_mc.lineTo(x, 50);
	clip_mc.lineTo(0, 50);
	clip_mc.lineTo(0, 0);
	clip_mc.endFill();
	r1 += rinc;
	g1 += ginc;
	b1 += binc;
}

That is amazing, and may I say this, you’ve obviously understod the code… as you’ve changed your footer to match!

yeah … it’s so sweet

i’m stoked that i finally understand something reasonably complex =)