flash on 2010-3-4
♥0 |
Line 233 |
Modified 2010-03-06 17:18:31 |
MIT License
archived:2017-03-30 08:09:58
ActionScript3 source code
/**
* Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/jqD1
*/
<?xml version="1.0" encoding="utf-8"?>
<!--
チューリングパターンの実験
簡単な方程式によって動物の模様などを再現することができる。
(未完成)
-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onLoad()">
<mx:Script>
<![CDATA[
import flash.display.*;
var time:Number;
var bmp_data:BitmapData
var bmp_obj:Bitmap;
var fCount:uint=0;
var a : Vector.<Vector.<uint> > = new Vector.<Vector.<uint> >(300);
var b : Vector.<Vector.<uint> > = new Vector.<Vector.<uint> >(300);
var na: Vector.<Vector.<uint> >= new Vector.<Vector.<uint> >(300);
var nb: Vector.<Vector.<uint> > = new Vector.<Vector.<uint> >(300);
var play:Boolean = true;
var processCount:uint =0;
var count:uint =0;
var aRed:int = 100;
var aBlue:int = 0;
var aGreen:int = 0;
var bRed:int = 0;
var bBlue:int = 100;
var bGreen:uint = 0;
var backRed:int = 255;
var backBlue:int = 255;
var backGreen:int = 255;
function onLoad():void{
addEventListener(Event.ENTER_FRAME, onEnterFrame);
var time:Number=getTimer();
stage.frameRate=24;
setBitmap();
setArray();
}
function onEnterFrame(e:Event):void{
if(play){count+=speedStepper.value;}
while(23<count){
count-=24;
process();
}
exFps();
bmpDrow();
}
function speedChanged():void{
}
function sliderChange(str:String):void{
}
//onLoadからの呼び出し
private function setBitmap():void{
bmp_data= new BitmapData( 300 , 300 , false , 0x000000);
bmp_obj = new Bitmap( bmp_data , PixelSnapping.AUTO , true);
canvas.addChild(bmp_obj);
}
private function setArray():void{
for(var x:uint = 0; x<300; x++){
a[x] = new Vector.<uint>(300);
b[x] = new Vector.<uint>(300);
na[x] = new Vector.<uint>(300);
nb[x] = new Vector.<uint>(300);
for(var y:uint = 0; y<300; y++){
a[x][y]=100;
b[x][y]=100;
}
}
bmpDrow();
}
//onEnterFrameからの呼び出し
private function exFps():void{
fCount++;
if(fCount>4){
var f:uint = fCount*1000/(getTimer()-time);
fps.text="fps:"+f +"/" + stage.frameRate;
time=getTimer();
fCount=0;
}
counter.text="counter:"+processCount;
}
private function bmpDrow():void{
bmp_data.lock();
for(var x:uint = 0; x<300; x++){
for(var y:uint = 0; y<300; y++){
var _red : uint = backRed - (a[x][y]*aRed + b[x][y]*bRed)/255;
var _green : uint = backGreen - (a[x][y]*aGreen + b[x][y]*bGreen)/255;
var _blue : uint = backBlue - (a[x][y]*aBlue - b[x][y]*bBlue)/255;
if(0>_red){_red=0;}
if(0>_green){_green=0;}
if(0>_blue){_blue=0;}
if(255<_red){_red=256;}
if(255<_green){_green=256;}
if(255<_blue){_blue=256;}
var color : uint = (_red << 16) | (_green << 8) | (_blue);
bmp_data.setPixel(x,y,color);
}
}
bmp_data.unlock();
}
private function process():void{
for(var x:uint = 0; x<300; x++){
for(var y:uint = 0; y<300; y++){
na[x][y]=Math.random()*255;
nb[x][y]=Math.random()*255;
}
}
a=na;
b=nb;
processCount++;
}
]]>
</mx:Script>
<mx:Label fontSize="23" text="Turing Pattarn"/>
<mx:VBox>
<mx:HBox>
<mx:VBox backgroundColor="0x000000"
paddingTop="10"
paddingBottom="10"
paddingLeft="10"
paddingRight="10">
<mx:UIComponent id="canvas" width="300" height="300"/>
</mx:VBox>
<mx:VBox>
<mx:VBox height="120"
borderStyle="solid"
paddingTop="5"
paddingBottom="5"
paddingLeft="5"
paddingRight="5">
<mx:HBox>
<mx:Label text="物質A" fontSize="19" />
</mx:HBox>
<mx:HBox>
<mx:Label width ="100" height="20" text="拡散速度"/>
<mx:HSlider width ="150" height="20"/>
<mx:TextInput width ="38" height="20"/>
</mx:HBox>
<mx:HBox>
<mx:Label width ="100" height="20" text="Aの合成促進(a)"/>
<mx:HSlider width ="150" height="20"/>
<mx:TextInput width ="38" height="20"/>
</mx:HBox>
<mx:HBox>
<mx:Label width ="100" height="20" text="Bの合成促進(c)"/>
<mx:HSlider width ="150" height="20"/>
<mx:TextInput width ="38" height="20"/>
</mx:HBox>
</mx:VBox>
<mx:VBox height="95"
borderStyle="solid"
paddingTop="5"
paddingBottom="5"
paddingLeft="5"
paddingRight="5">
<mx:HBox>
<mx:Label text="物質B" fontSize="19" />
</mx:HBox>
<mx:HBox>
<mx:Label width ="100" height="20" text="拡散速度"/>
<mx:HSlider width ="150" height="20"/>
<mx:TextInput width ="38" height="20"/>
</mx:HBox>
<mx:HBox>
<mx:Label width ="100" height="20" text="Aの合成阻害(b)"/>
<mx:HSlider width ="150" height="20"/>
<mx:TextInput width ="38" height="20"/>
</mx:HBox>
</mx:VBox>
<mx:VBox>
<mx:HBox horizontalGap="2">
<mx:VBox>
<mx:Label id="counter" width ="90" height="16" text="counter:0"/>
<mx:Label id="fps" width ="90" height="16" text="FPS:24/24"/>
<mx:HBox width="120">
<mx:Label width ="45" height="18" text="再生速度"/>
<mx:NumericStepper id="speedStepper" change="speedChanged();" width ="45" height="20" maximum="100" minimum="1" value="24" stepSize="1"/>
</mx:HBox>
</mx:VBox>
<mx:Button width ="95" height="65" fontSize="18" label="RESET"/>
<mx:Button width ="95" height="65" fontSize="18" label="START"
fillAlphas="[0.8, 0.7]"
fillColors="[0xFFDDDD, 0xFF8844]"
/>
</mx:HBox>
</mx:VBox>
</mx:VBox>
</mx:HBox>
</mx:VBox>
<mx:VBox>
<mx:HBox>
<mx:ToggleButtonBar
borderStyle="solid"
horizontalGap="2"
toggleOnClick="true"
selectedIndex="0">
<mx:dataProvider>
<mx:String>物質A</mx:String>
<mx:String>物質B</mx:String>
<mx:String>消しゴム</mx:String>
</mx:dataProvider>
</mx:ToggleButtonBar>
<mx:Button label="全消去"/>
</mx:HBox>
<mx:VBox borderStyle="solid"
paddingTop="10"
paddingBottom="10"
paddingLeft="10"
paddingRight="10">
<mx:Label fontSize="12" text="ペンの設定"/>
<mx:HBox>
<mx:VBox>
<mx:Canvas width="50" height="50" backgroundColor="0x000000" />
<mx:Button label="色の設定"/>
</mx:VBox>
<mx:VBox>
<mx:HBox>
<mx:Label width ="50" height="20" text="サイズ" textAlign="right"/>
<mx:HSlider width ="100" height="20"/>
<mx:TextInput width ="38" height="20"/>
</mx:HBox>
<mx:HBox>
<mx:Label width ="50" height="20" text="濃さ" textAlign="right"/>
<mx:HSlider width ="100" height="20"/>
<mx:TextInput width ="38" height="20"/>
</mx:HBox>
<mx:HBox>
<mx:Label width ="50" height="20" text="乱数" textAlign="right"/>
<mx:HSlider width ="100" height="20"/>
<mx:TextInput width ="38" height="20"/>
</mx:HBox>
</mx:VBox>
</mx:HBox>
</mx:VBox>
</mx:VBox>
</mx:Application>