// Mouse stalker with transform by flash.geom.Matrix // マウスを追跡するオブジェクトが、その移動距離に応じて変形する。 // 変形は Matrix.b と Matrix.c によっておこなわれる。 // マウスをなるべく斜めにならないように垂直もしくは水平に動かすと、変形の具合が分かりやすい。 package { /** * @author YOSHIDA, Akio */ import flash.display.Shape; import flash.display.Sprite; import flash.geom.Matrix; import flash.events.Event; [SWF(width = "465", height = "465", frameRate = "45", backgroundColor = "#000000")] public class Main extends Sprite { private var shp:Shape; private var m:Matrix; private var vx:Number = 0; private var vy:Number = 0; private var spring:Number = 0.0075; private var friction:Number = 0.95; public function Main():void { Wonderfl.capture_delay(10); shp = new Shape(); draw(shp); addChild(shp); m = new Matrix(); m.tx = stage.stageWidth / 2; m.ty = stage.stageHeight / 2; addEventListener(Event.ENTER_FRAME, enterFrameHandler); } private function draw(target:Shape):void { var size:uint = 80; target.graphics.beginFill(Math.random()*0xffffff); target.graphics.drawRect(-size/2, -size/2, size, size); target.graphics.endFill(); } private function enterFrameHandler(e:Event):void { vx += (mouseX - shp.x) * spring; vx *= friction; vy += (mouseY - shp.y) * spring; vy *= friction; m.tx += vx; m.ty += vy; m.c = -vx * 0.1; m.b = -vy * 0.1; shp.transform.matrix = m; } } } Mouse stalker 001