GenWood2
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;
[SWF(width=465, height=465, frameRate=24, backgroundColor=0x240c00)]
public class GenWood extends Sprite
{
public var woods:Array = new Array();
public var wood:ControllWood;
public var cnt:int = 0;
public function GenWood()
{
init();
}
public function init():void
{
wood = new ControllWood(230, 430);
addEventListener(Event.ENTER_FRAME, growWood);
woods.push(wood);
stage.addEventListener(MouseEvent.MOUSE_UP, reset);
}
public function reset(e:MouseEvent):void
{
graphics.clear();
cnt = 0;
woods = new Array();
//trace(woods[0]);
removeEventListener(Event.ENTER_FRAME, growWood);
stage.removeEventListener(MouseEvent.MOUSE_UP, reset);
stage.addEventListener(MouseEvent.MOUSE_UP, restart);
}
public function restart(e:MouseEvent):void
{
init();
stage.removeEventListener(MouseEvent.MOUSE_UP, restart);
}
public function growWood(e:Event):void
{
var woodsLength:Number = woods.length;
for(var i:int; i < woodsLength; i++)
{
woods[i].x += -5 + Math.random() * 10;
woods[i].y += -3;
//=========oldXとの差から、曲がる傾向を加算=========
woods[i].revise = woods[i].x - woods[i].oldX;
woods[i].revise *= cnt / 100;
woods[i].x += woods[i].revise;
woods[i].oldX = woods[i].x;
var col:Number = 0xffffff * Math.random() * mouseY / 50;
var rad:Number = 4 + Math.random()*5 * mouseX / 200;
var alp:Number = 0.3;
drawWood(col, alp, woods[i].x, woods[i].y, rad, 1);
cnt++;
//==========小枝を増やす============
if(cnt > 35 && woodsLength < 13 && Math.random() < 0.03)
{
var childWood:ControllWood = new ControllWood(woods[i].x + 20, woods[i].y);
woods.push(childWood);
}
//===============花を咲かす============
if(cnt > 90 && Math.random() < 0.17)
{
var col2:Number = 0xFF6600 + 0x001111 * Math.random();
var rad2:Number = 20;
var chen:Number = -60 + Math.random()*120;
//========裏側の花==========
drawWood(col2, Math.random()-0.4, woods[i].x + chen, woods[i].y - 20, rad2 * 1.5, Math.random() );
//========手前の花=========
drawWood(col2, Math.random()-0.4, woods[i].x + chen, woods[i].y + 20, rad2, Math.random() );
}
if(woods[i].y < 0)
{
removeEventListener(Event.ENTER_FRAME, growWood);
}
}
}
public function drawWood(wc:Number, wa:Number, wsx:Number, wsy:Number, wr:Number, lineA:Number):void
{
graphics.lineStyle(0.1, wc, lineA );
graphics.beginFill(wc, wa );
graphics.drawCircle(wsx, wsy, wr);
graphics.endFill();
}
}
}
//=========ControllWoodクラス===========
class ControllWood
{
public var x:Number;
public var y:Number;
public var oldX:Number;
public var oldY:Number;
public var revise:Number;
public function ControllWood(wx:Number, wy:Number)
{
x = wx;
y = wy;
oldX = wx;
oldY = wy;
revise = 0;
}
}