In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

雑に一筆書き

一筆書きで画像を書く。
* 起動後1、2秒くらい座標計算します。
* 画像の埋め込みはclockmakerさんのクラスを使用させていただきました。
* http://wonderfl.kayac.com/code/cf21d213336193c264cd1e2e6031615609603ce2
/**
 * Copyright demouth ( http://wonderfl.net/user/demouth )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pAiw
 */

// forked from egyu2's 一筆書き(鉛筆風)
/**
 * 一筆書きで画像を書く。
 * 起動後1、2秒くらい座標計算します。
 * 画像の埋め込みはclockmakerさんのクラスを使用させていただきました。
 * http://wonderfl.kayac.com/code/cf21d213336193c264cd1e2e6031615609603ce2
 */
package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	public class Main extends Sprite 
	{
		
		private var image:Bitmap;
		private var processingText:TextField;
		private var v:Vector.<Point> = new Vector.<Point>();
		private const DATA:String = "iVBORw0KGgoAAAANSUhEUgAAAHoAAACVCAMAAACglR6BAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAwBQTFRFX38/msxmKgVFWRl9KwEBTAEBOQpbOVxcepxUTGYzSFhYLz4foNBsHScSlshjYYM8VBV5VXQzU203JAQ9jrxZNEQiEgMcfqdNNU5OTmstHx8fptRxwA4OAAAAtQoKxRAQWHM9////n89rkL5bgKhWdp9NMwlSM5mZGwMsQlwlZYg+W3s2KjUcpAQEPgtilgkJExkML0AaDAISgq1VGAYig61RqgYGQAEBQlksFgAARl0tgatRDRMHfAEBWHU3ngICCQwGFQIkIAU0CwEBBgEJCAENmcxmQQxmjbpYqdZ0Yh2GBAAHGUxMJnJyD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iMJXcMhXGD1eLJJ8mXmuuGOltR5/c/GGj0KUrKKjK42+vfi2V5Gai46ttId/eHz8bXdbnSq++OhXx8dv/OylQT81Pl68FOgoZk3U+rlLgB4D2DU+bqoSVgLNYc7+KK705i4BGgup3Xevtjw2f7HRY1LVxl0CNPnvGjLW/03BRUejl9u8/mMBBgARytbjGhiiHQAAAABJRU5ErkJggg=="
		private var loader:Loader;
		private const SCALE:Number = 3.1;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			Wonderfl.capture_delay( 100 );
			this.loader = Base64ImageLoader.load(this.DATA) as Loader;
			
			this.processingText = new TextField();
			this.processingText.htmlText = "<font size='14'>座標計算中</font>";
			this.addChild(this.processingText);
			
			this.loader.addEventListener(Event.ADDED , this.onLoad );
		}
		
		private function onLoad(event:Event):void
		{
			this.removeChild(this.processingText);
			this.image = (this.loader).content as Bitmap;
			this.addChild(this.image);
			
			this.checkColor();
			this.v = this.sort();
			var d:Drawer = new Drawer(this.v , this.image.width , this.image.height, this.SCALE);
			this.addChild(d);
			this.image.scaleX = this.image.scaleY = this.SCALE;
			this.image.alpha = 0.15;
		}
		
		/**
		 * 描画するドットを決定
		 */
		private function checkColor():void
		{
			var w:uint = this.image.width;
			var h:uint = this.image.height;
			var r:uint = 0;
			var g:uint = 0;
			var b:uint = 0;
			
			for (var i:int = 0; i < h; i++) 
			{
				for (var j:int = 0; j < w; j++) 
				{
					var color:uint = this.image.bitmapData.getPixel(j, i);
					r = ( color >> 16 ) & 0xFF;
					g = ( color >> 8 ) & 0xFF;
					b = ( color ) & 0xFF;
					if ( (r + g + b) < 10 )this.v.push(new Point(j, i));//閾値以下なら描画用の座標に格納
				}
			}
		}
		
		private function sort():Vector.<Point>
		{
			var length:int = this.v.length;
			var tmp:Vector.<Point> = new Vector.<Point>();
			var nowPoint:Point = new Point();
			for (var i:int = 0; i < length; i++) 
			{
				var num:int = this.check(nowPoint);
				nowPoint = this.v[num];
				tmp.push(this.v.splice(num, 1)[0]);
			}
			return tmp;
		}
		
		/**
		 * 一番近いドットを決定
		 */
		private function check(p:Point):int
		{
			var near:uint;
			var nearDiff:int;
			var length:uint = this.v.length;
			
			var diffX:int = 0;
			var diffY:int = 0;
			var diff:int = 0;
			for (var i:int = 0; i < length; i++) 
			{
				diffX = this.v[i].x - p.x;
				diffY = this.v[i].y - p.y;
				diff = Math.sqrt((diffX * diffX) + (diffY * diffY));
				
				if (diff < nearDiff || (i == 0))
				{
					nearDiff = diff;
					near = i;
				}
			}
			return near;
		}
		
	}
	
}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
class Drawer extends Sprite
{
	private var v:Vector.<Point>;
	private var bitmap:Bitmap;
	private var brush:Sprite;
	private var w:Number;
	private var h:Number;
	private var num:int = 0;
	private var vX:Number = 0;
	private var vY:Number = 0;
	private var scale:Number = 1;
	private const ZATSU:Number = 10;//雑具合。高いと雑になる。
	
	public function Drawer(v:Vector.<Point> , w:Number , h:Number , scale:Number) 
	{
		this.v = v;//座標
		this.w = w;//画像の幅
		this.h = h;//画像の高さ
		this.scale = scale;//描画するサイズ
		this.init();
	}
	
	private function init():void
	{
		var bitmapData:BitmapData = new BitmapData(this.w*this.scale, this.h*this.scale, true,0x00000000);
		this.bitmap = new Bitmap(bitmapData);
		this.addChild(this.bitmap);
		
		this.brush = new Sprite();
		this.addChild(this.brush);
		this.brush.graphics.beginFill(0, 1);
		this.brush.graphics.drawCircle(0,0,2);
		this.brush.graphics.endFill();
		
		var length:int = this.v.length;
		for (var i:int = 0; i < length; i++) 
		{
			this.v[i].x *= this.scale;
			this.v[i].y *= this.scale;
		}
		
		this.addEventListener(Event.ENTER_FRAME , onEnterFrame);
	}
	
	private function onEnterFrame(event:Event):void
	{
		if(this.num < this.v.length){
			var p:Point = this.v[this.num];
			this.vX += (p.x - this.brush.x) * 0.1;
			this.vY += (p.y - this.brush.y) * 0.1;
			this.vX *= 0.85;
			this.vY *= 0.85;
			this.brush.x += this.vX;
			this.brush.y += this.vY;
			this.bitmap.bitmapData.draw(this);
			var diffX:int = p.x - this.brush.x;
			var diffY:int = p.y - this.brush.y;
			var diff:Number = Math.sqrt((diffX * diffX) + (diffY * diffY));
			if(diff < this.ZATSU)this.num++;
		} else {
			this.removeEventListener(Event.ENTER_FRAME , onEnterFrame);
		}
	}
	
}

/**
 * Base64化された画像データを表示可能な形式に変換するクラス
 * 
 * 使い方 :
 * var data:String = "Base64化された画像データ";
 * var display:DisplayObjectContainer = Base64ImageLoader.load(data);
 * if (display != null)
 *     addChild(display);
 */
class Base64ImageLoader
{
	import flash.display.DisplayObjectContainer;
	import flash.display.Loader;
	import flash.utils.ByteArray;
	import mx.utils.Base64Decoder;
	static public function load(data:String):DisplayObjectContainer
	{
		var byteArray:ByteArray;
		var base64Decoder:Base64Decoder;
		var loader:Loader;
		
		base64Decoder = new Base64Decoder();
		base64Decoder.decode(data);
		
		try {
			byteArray = base64Decoder.toByteArray();
			byteArray.position = 0;
		} catch (e:Error) {
			return null;
		}
		
		loader = new Loader();
		loader.loadBytes(byteArray);
		
		return loader;
	}
}