Draw and Generate
ステージをドラックすると絵が描けます
個々の絵が個別のスプライトになって保存される
svnの代わりにwonderflにup
/**
* Copyright kappaLab ( http://wonderfl.net/user/kappaLab )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/kS4F
*/
/*
ステージをドラックすると絵が描けます
個々の絵が個別のスプライトになって保存される
svnの代わりにwonderflにup
*/
package
{
import flash.display.Graphics;
import flash.display.SpreadMethod;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
public class DrawCreature extends Sprite
{
private var gr:Graphics
private var sX:Number;
private var sY:Number;
private var mX:Number;
private var mY:Number;
private var eX:Number;
private var eY:Number;
private var posints:Vector.<Vector.<Number>>
private var drawingEnable:Boolean = false;
public function DrawCreature()
{
stage.scaleMode = "noScale";
hitArea = new Sprite();
hitArea.graphics.beginFill(0x000000);
hitArea.graphics.drawRect(0, 0, 1000, 1000);
addChild(hitArea)
gr = Sprite(addChild(new Sprite())).graphics
gr.lineStyle(1,0xFF0000)
mX = mY = 0
addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown)
addEventListener(MouseEvent.MOUSE_UP, onMouseUp)
addEventListener(Event.ENTER_FRAME, onEnterframe)
}
private function onEnterframe(e:Event):void
{
if (!drawingEnable) return;
var mouseX:Number = this.mouseX
var mouseY:Number = this.mouseY
var dX:Number = (mouseX-mX)
var dY:Number = (mouseY-mY)
var distance:Number = Math.sqrt(dX*dX+dY*dY)
if (distance < 10) return;
var point:Vector.<Number> = new Vector.<Number>(2)
point[0] = mX
point[1] = mY
posints.push(point);
gr.moveTo(mX, mY);
gr.lineTo(mouseX, mouseY);
mX = mouseX;
mY = mouseY;
}
private function onMouseUp(e:MouseEvent):void
{
drawingEnable = false
var point:Vector.<Number> = new Vector.<Number>(2)
point[0] = mX
point[1] = mY
posints.push(point);
gr.clear()
if (posints.length < 2) return;
addChild(new Creature(posints))
}
private function onMouseDown(e:MouseEvent):void
{
drawingEnable = true
gr.lineStyle(1,0xFF0000)
sX = mX = e.stageX
sY = mY = e.stageY
posints = new Vector.<Vector.<Number>>()
}
}
}
import flash.display.*
import flash.events.Event;
class Creature extends Sprite
{
public var points:Vector.<Vector.<Number>>
private var gr:Graphics
public function Creature(points:Vector.<Vector.<Number>>)
{
this.points = points
gr = this.graphics
gr.lineStyle(1,0x00FF00)
//addEventListener(Event.ENTER_FRAME,onEnterFrame)
gr.moveTo(points[0][0],points[0][1])
var n:int = points.length
for (var i:int = 1; i < n; i++)
{
gr.lineTo(points[i][0],points[i][1])
}
gr.lineTo(points[0][0],points[0][1])
}
private function draw():void
{
gr.moveTo(points[0][0],points[0][1])
var n:int = points.length
for (var i:int = 1; i < n; i++)
{
gr.lineTo(points[i][0],points[i][1])
}
gr.lineTo(points[0][0],points[0][1])
}
private function onEnterFrame(e:Event):void
{
for each(var p:Vector.<Number> in points)
{
}
}
}