雑ライン -slipsod lines-
LIVE CODING 2010/04/20 21:00~23:10
クリックで色が変わります。
雑なラインしか書けませんが好きな絵を描いていってください。
Click to change color and enjoy drowing!!
/**
* Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zkM2
*/
package {
//LIVE CODING 2010/04/20 21:00~23:10
//クリックで色が変わります。
//雑なラインしか書けませんが好きな絵を描いていってください。
//Click to change color and enjoy drowing!!
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
stage.addChild( new Paper() );
Wonderfl.capture_delay( 10 );
}
}
}
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.filters.BlurFilter;
class Paper extends Bitmap{
public var lineType:String = "zatu";
private var lineSegmentsX:Vector.<Number>;
private var lineSegmentsY:Vector.<Number>;
private var lines:Vector.<ZatuLine>;
private var down:Boolean = false;
private var count:uint = 0;
private var color:uint = 0xFF0000;
public function Paper():void{
addEventListener( Event.ADDED_TO_STAGE, init );
}
private function init(e:Event):void{
removeEventListener( Event.ADDED_TO_STAGE, init );
bitmapData = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x000000 );
addEventListener( Event.ENTER_FRAME, onFrame );
parent.addEventListener( MouseEvent.MOUSE_DOWN, onDown );
parent.addEventListener( MouseEvent.MOUSE_MOVE, onMove );
parent.addEventListener( MouseEvent.MOUSE_UP, onUp );
lineSegmentsX = new Vector.<Number>();
lineSegmentsY = new Vector.<Number>();
lines = new Vector.<ZatuLine>();
}
private function onFrame(e:Event):void{
if(down){
var dise:int = Math.random() * 7;
switch(dise){
case 0:
color = 0xFFFFFF;
break;
case 1:
color = 0x00FFFF;
break;
case 2:
color = 0xFF00FF;
break;
case 3:
color = 0xFFFF00;
break;
case 4:
color = 0xFF0000;
break;
case 5:
color = 0x00FF00;
break;
case 6:
color = 0x0000FF;
break;
}
}
if(lineType == "zatu"){
bitmapData.lock();
bitmapData.fillRect(bitmapData.rect, 0x00);
for each(var line:ZatuLine in lines ) {
line.draw(bitmapData);
}
bitmapData.unlock();
}
}
private function onMove(e:Event):void{
lineSegmentsX.push(mouseX);
lineSegmentsY.push(mouseY);
var length:int = lineSegmentsX.length;
if(length > 10){
var zatuline:ZatuLine = new ZatuLine( lineSegmentsX[length - 5],lineSegmentsY[length - 5],
lineSegmentsX[length-1],lineSegmentsY[length-1]
);
zatuline.color = color;
lines.push(zatuline);
lineSegmentsX.shift();
lineSegmentsY.shift();
}
if(lines.length > 300){
lines.shift();
}
}
private function onDown(e:Event):void{
down = true;
switch(lineType){
case "zatu":
break;
}
}
private function onUp(e:Event):void{
down = false;
}
}
import flash.filters.BlurFilter;
class ZatuLine{
private var startX:Number;
private var startY:Number;
private var endX:Number;
private var endY:Number;
public var aboutness:Number = 3;
public var color:uint = 0x000000;
public function ZatuLine( sx:Number, sy:Number, ex:Number, ey:Number ):void{
startX = sx;
startY = sy;
endX = ex;
endY = ey;
}
public function draw( bitmapData:BitmapData ):void{
var shape:Shape = new Shape();
with(shape.graphics){
lineStyle(1,color, Math.random()*0.6 );
moveTo( startX+(Math.random()*2 - 1) * aboutness , startY+(Math.random()*2 - 1) * aboutness );
lineTo( endX+(Math.random()*2 - 1) * aboutness , endY+(Math.random()*2 - 1) * aboutness );
}
bitmapData.draw(shape);
}
}