Patern Generator
♥6 |
Line 79 |
Modified 2009-09-15 13:50:05 |
MIT License
archived:2017-03-07 21:13:11
ActionScript3 source code
/**
* Copyright clockmaker ( http://wonderfl.net/user/clockmaker )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/8TK2
*/
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="465" height="465" creationComplete="atReady(event)">
<!-- ===============================================
パターンジェネレーター Patern Generator
================================================ -->
<mx:Script>
<![CDATA[
import flash.display.Bitmap;
import flash.display.BitmapData;
import mx.utils.ColorUtil;
import mx.graphics.codec.PNGEncoder;
import mx.events.ListEvent;
import mx.collections.ArrayCollection;
private var paint:BitmapData;
protected function atReady(event:Event):void
{
combo.dataProvider = new ArrayCollection([{name:"0 or 1"}, {name:"○ or ●"}]);
}
protected function loadImage(event:MouseEvent):void
{
// ローカル画像の読み込み
var fr:FileReference = new FileReference();
fr.browse();
fr.addEventListener("select", function():void { fr.load(); });
fr.addEventListener("complete", function():void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener("init", function():void {
paint = Bitmap(loader.content).bitmapData.clone();
loader.unload();
convert();
});
loader.loadBytes(fr.data);
});
}
protected function copyCheckmate(event:MouseEvent):void
{
convert();
System.setClipboard(jsonText.text);
}
protected function convert():void
{
if (paint == null) return;
var p:Array = [];
var i:int, j:int, k:int;
for(i=0; i<paint.height; i++)
{
p[i] = [];
for(j=0; j<paint.width; j++)
{
p[i][j] = (paint.getPixel32(j,i) == 0x00000000);
}
}
var onLabel:String = combo.selectedIndex == 1 ? "'●'" : "1";
var offLabel:String = combo.selectedIndex == 1 ? "'○'" : "0";
// for text
var str:String = "[\n";
for(i=0; i<p.length; i++)
{
str += " " + "[";
for (j = 0; j < p[i].length; j++)
{
str += (j==0 ? "" : ",") + ((p[i][j]) ? offLabel : onLabel);
}
str += "]"+ (i==p.length-1 ? "" : ", ") + "\n";
}
str += "]";
jsonText.text = str;
}
private function changeComboHandler():void
{
convert();
}
]]>
</mx:Script>
<mx:Panel title="Patern Array Generator" paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5" width="100%" height="100%">
<mx:ComboBox id="combo" labelField="name" change="changeComboHandler()" />
<mx:Button label="Load Image" click="loadImage(event)" toolTip="ローカルの画像を読み込んでパターンに使用します" />
<mx:TextArea id="jsonText" width="100%" height="100%" fontSize="8" />
<mx:Button label="Copy Patern Array" click="copyCheckmate(event)" toolTip="パターンJSONをコピーします" />
</mx:Panel>
</mx:Application>