curveTo とかベジェとか soundkitchen.. forked:2favorite:7lines:121license : All rights reserved modified : 2009-03-28 01:08:38 Embed Tweet package { import flash.display.Graphics; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Point; import flash.text.TextField; import flash.text.TextFieldAutoSize; import flash.text.TextFormat; [SWF(frameRate=30, width=465, height=465, backgroundColor=0xffffff)] public class Main extends Sprite { private var points:Vector.<Sprite>; public function Main() { addEventListener(Event.ADDED_TO_STAGE, initialize); } private function initialize(evt:Event):void { removeEventListener(Event.ADDED_TO_STAGE, initialize); points = new Vector.<Sprite>(); var info:TextField = new TextField(); info.text = "click で作って、 drag で動かす。\n要らなくなったら shift + click で消せるよ。"; info.autoSize = TextFieldAutoSize.LEFT; info.y = stage.stageHeight - info.textHeight; addChild(info); addEventListener(Event.ENTER_FRAME, step); stage.addEventListener(MouseEvent.CLICK, stageClickHandler); } private function step(evt:Event):void { var i:uint, l:uint, g:Graphics, ps:Sprite, cs:Sprite, pp:Point, cp:Point; g = graphics; g.clear(); l = points.length; for (i=1; i<l; i++) { ps = points[i-1]; cs = points[i]; g.lineStyle(1, 0xd8d8d8); g.moveTo(ps.x, ps.y); g.lineTo(cs.x, cs.y); cp = new Point(); cp.x = ps.x + (cs.x - ps.x) / 2; cp.y = ps.y + (cs.y - ps.y) / 2; g.lineStyle(1, 0x4c4c4c); if (pp) { g.moveTo(pp.x, pp.y); g.curveTo(ps.x, ps.y, cp.x, cp.y); } else { g.moveTo(ps.x, ps.y); g.lineTo(cp.x, cp.y); } pp = cp; } if (cs) { g.moveTo(cp.x, cp.y); g.lineTo(cs.x, cs.y); } } private function leave(s:Sprite):void { var i:uint; removeChild(s); i = points.indexOf(s); points.splice(i, 1); s.removeEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); s.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); s.removeEventListener(MouseEvent.CLICK, clickHandler); } private function mouseDownHandler(evt:MouseEvent):void { var s:Sprite = Sprite(evt.target); if (evt.shiftKey) { leave(s); } else { s.startDrag(); } } private function mouseUpHandler(evt:MouseEvent):void { stopDrag(); } private function clickHandler(evt:MouseEvent):void { evt.stopPropagation(); } private function stageClickHandler(evt:MouseEvent):void { var s:Sprite, g:Graphics; s = new Sprite(); s.x = mouseX; s.y = mouseY; s.buttonMode = true; s.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); s.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); s.addEventListener(MouseEvent.CLICK, clickHandler); g = s.graphics; g.beginFill(0x000000); g.drawCircle(0, 0, 3); g.endFill(); points.push(s); addChild(s); } } } Code Fullscreen Preview Fullscreen tjoen plankton miyaoka y_tti clockmaker : ベジェ曲線を作る szusz : curves whirlpower : 勉強させていただきます。 Graphics bezier curveTo curves stopPropagation MouseEvent.CLICK MouseEvent.ADDED_TO_STAGE MouseEvent shiftKey MouseEvent.MOUSE_UP MouseEvent.MOUSE_DOWN startDrag stopDrag buttonMode indexOf graphics addEventListener removeChild removeEventListener target splice mouseY MouseEvent.ENTER_FRAME mouseX sort new page view favorite forked pv381 forked from: curveTo とかベジェとか soundkitchen forked:1 favorite:4lines:159 (diff:48) tag: curve pv176 forked from: curveTo とかベジェとか syROBO forked:0 favorite:0lines:121 (diff:1)