Random Grid コードは汚いので見ないでほしい・・・ mousepancyo forked:0favorite:10lines:118license : MIT License modified : 2011-04-25 15:52:35 Embed Tweet package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.Event; import flash.geom.Point; import flash.geom.Rectangle; import flash.utils.Dictionary; [SWF(width = "465", height = "465", backgroundColor = "0xFFFFFF", frameRate = "60")] public class Main extends Sprite { private const MAX_NUM:int = 15; private const LIMIT_SIZE:Number = 30; private var _canvas:BitmapData; private var _points:Vector.<Point> = Vector.<Point>([]); private var _dict:Dictionary = new Dictionary(true); public function Main() { setup(); } private function setup():void { _canvas = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xFFFFFF); addChild(new Bitmap(_canvas)); addPoint(0xAA0000, stage.stageWidth * (Math.random() * .4 + .3), stage.stageHeight * (Math.random() * .4 + .1), 2, 2); addEventListener(Event.ENTER_FRAME, update); } private function addPoint(cl:int, px:Number, py:Number, d:int, c:int):void { var p:Point = new Point(px, py); var color:int = cl >> 8; if(color < 0xAA) color = 0xAA0000 _dict[p] = {col:color, startX:p.x, startY:p.y, dir:d, change:c}; _points.push(p); } private function update(e:Event):void { drawLine(); } private function drawLine():void { var n:int = _points.length; if(n == 0){ removeEventListener(Event.ENTER_FRAME, update); return; } _canvas.lock(); while(n--){ var p:Point = _points[n]; if(_dict[p].dir == 2){ if(_dict[p].change == 2){ p.y +=3; }else{ p.y -=3; } }else{ if(_dict[p].change == 2){ p.x +=3; }else{ p.x -=3; } } // var x1:Number = 0; var x2:Number = 0; var y1:Number = 0; var y2:Number = 0; var cl:int = _dict[p].col; if(_dict[p].dir == 1){ if(p.y < 0 || p.y > stage.stageHeight || _canvas.getPixel(p.x, p.y) != 0xFFFFFF || _canvas.getPixel(p.x + 1, p.y + 1) != 0xFFFFFF || _canvas.getPixel(p.x - 1, p.y - 1) != 0xFFFFFF ){ if(_dict[p].change == 2){ x1 = (p.x - _dict[p].startX) * (Math.random() * .8 + .1) + _dict[p].startX; x2 = (p.x - _dict[p].startX) * (Math.random() * .8 + .1) + _dict[p].startX; }else{ x1 = (_dict[p].startX - p.x) * (Math.random() * .8 + .1) + p.x; x2 = (_dict[p].startX - p.x) * (Math.random() * .8 + .1) + p.x; } if(_points.length < MAX_NUM && Math.abs(_dict[p].startX - p.x) > LIMIT_SIZE){ addPoint(cl, x1, p.y, 2, 1); addPoint(cl, x2, p.y, 2, 2); } _points.splice(n, 1); return; }else{ _canvas.fillRect(new Rectangle(p.x, p.y, 2, 1), _dict[p].col); } }else{ if(p.x < 0 || p.x > stage.stageWidth || _canvas.getPixel(p.x, p.y) != 0xFFFFFF || _canvas.getPixel(p.x + 1, p.y + 1) != 0xFFFFFF || _canvas.getPixel(p.x - 1, p.y - 1) != 0xFFFFFF ){ if(_dict[p].change == 2){ y1 = (p.y - _dict[p].startY) * (Math.random() * .8 + .1) + _dict[p].startY; y2 = (p.y - _dict[p].startY) * (Math.random() * .8 + .1) + _dict[p].startY; }else{ y1 = (_dict[p].startY - p.y) * (Math.random() * .8 + .1) + p.y; y2 = (_dict[p].startY - p.y) * (Math.random() * .8 + .1) + p.y; } if(_points.length < MAX_NUM && Math.abs(_dict[p].startY - p.y) > LIMIT_SIZE){ addPoint(cl, p.x, y1, 1, 1); addPoint(cl, p.x, y2, 1, 2); } _points.splice(n, 1); return; }else{ _canvas.fillRect(new Rectangle(p.x, p.y, 1, 2), _dict[p].col); } } } _canvas.unlock(); } } } Code Fullscreen Preview Fullscreen ton_ osamX kleinschmidt.. skn satosu siouxcitizen.. Nyarineko novita001 lespleen : grid qwertyui : CODE CODE grid Dictionary splice Math.abs Rectangle length removeEventListener Event.ENTER_FRAME addEventListener Math.random push addChild Event Vector Sprite int Number