package { import com.flashdynamix.motion.Tweensy; import flash.display.Shape; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Matrix; import flash.geom.Point; /** * 朝からワンダフルで朝方生活になる!朝ワン! * Matrix の勉強! * クリック! */ public class FlashTest extends Sprite { private var sp: Sprite; private var mode: int; private var points: Array = []; private var shapes: Array = []; public function FlashTest() { // write as3 code here.. if (stage) init(); else addEventListener(Event.ADDED_TO_STAGE, init); } private function init(e: Event = null): void { removeEventListener(Event.ADDED_TO_STAGE, init); sp = new Sprite(); for (var ix: int = 0; ix < 6; ix++) { for (var iy: int = 0; iy < 4; iy++) { var sh: Shape = new Shape(); sh.graphics.beginFill(0xFF0000, 1); sh.graphics.drawCircle(0, 0, 10); sh.x = ix * 50; sh.y = iy * 50; sp.addChild(sh); points.push(new Point(sh.x, sh.y)); } } sp.x = 40; sp.y = 40; addChild(sp); stage.addEventListener(MouseEvent.CLICK, onClick); mode = 0; } private function onClick(e: MouseEvent): void { var i: int, n: int, sh: Shape; switch (mode) { case 0: sp.transform.matrix = new Matrix(0.91, 0.42, -0.71, 0.71, 150, 60); break; case 1: n = points.length; for (i = 0; i < n; i ++) { sh = new Shape(); sh.x = points[i].x; sh.y = points[i].y; sh.graphics.beginFill(0x0000FF, 1); sh.graphics.drawCircle(0, 0, 5); addChild(sh); shapes.push(sh); } break; case 2: n = points.length; var matrix: Matrix = new Matrix(0.91, 0.42, -0.71, 0.71, 150, 60); for (i = 0; i < n; i ++) { sh = shapes[i]; var ix: int = i / 4; var iy: int = i % 4; Tweensy.to(sh, { x: ix * 50 * matrix.a + iy * 50 * matrix.c + matrix.tx }, 2 ); Tweensy.to(sh, { y: ix * 50 * matrix.b + iy * 50 * matrix.d + matrix.ty }, 2 ); } break; } mode ++; } } } [朝ワン] Matrix の勉強