Another Matrix.transformPoint()

[SWF(width = 628, height=500)]
var trans:Matrix = new Matrix();
var pnt:Point = new Point();
x = stage.stageWidth / 2;
y = stage.stageHeight / 2;
addEventListener(Event.ENTER_FRAME, onLoop);
function onLoop(evt:Event):void {
	graphics.clear();
	graphics.lineStyle(10, 0x000000, 1, false, LineScaleMode.NORMAL, CapsStyle.SQUARE);
	pnt.x = 0;
	pnt.y = 0;
	trans.identity();
	trans.translate(15,15);
	trans.rotate(mouseX/10 * Math.PI / 180);
	graphics.moveTo(pnt.x, pnt.y);
	for (var i:int = 0; i<12; i++){
		pnt = trans.transformPoint(pnt);
		graphics.lineTo(pnt.x, pnt.y);
	}
}

I was thinking about processing and OpenGL today… I always really enjoyed using matrix stuff, working with the matrix stack, using push() and pop() etc… Understanding how to use matrices is pretty important when your doing advanced graphics in actionscript. If you haven’t messed with matrices, this snippet is a good place to start. It uses Matrix.transformPoint() to draw a series of connected lines that are controlled by the x location of the mouse. Back before flash 8, this kind of thing was usually done using trig or MovieClip nesting…

I posted another snippet on this topic awhile back.

2 comments

Leave a Reply

Your email address will not be published. Required fields are marked *