Bitmapのテスト awef forked:3favorite:1lines:124license : MIT License modified : 2009-03-10 08:29:26 Embed Tweet package { import flash.display.*; import flash.events.*; public class main extends Sprite { public var Cluster:Object = {}; private var bmp_data:BitmapData; private var bmp:Bitmap; function main() { bmp_data = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xFFFFFF); bmp = new Bitmap(bmp_data); stage.addChild(bmp); stage.addEventListener(Event.ENTER_FRAME, frame); for(var i:uint = 0; i < 45; i++) { stage.addChild(new ball( Cluster, stage, Math.floor(Math.random() * stage.stageWidth), Math.floor(Math.random() * stage.stageHeight), 10, Math.floor(Math.random() * 0xFFFFFF), 4 )); } } private function frame(e:Event):void { bmp_data.draw(stage); bmp.bitmapData = bmp_data; } } } import flash.display.*; import flash.events.*; //import flash.geom.Point; class Cluster_item extends Sprite { protected var Cluster:Object; public function addToCluster(name:String):void { //todo:重複防止 if(Cluster[name] == null) Cluster[name] = [this]; else Cluster[name].push(this); } /*未実装 public function removeFromCluster(name:String):void { } */ public function remove():void { beforeRemove(); stage.removeChild(this); } public function beforeRemove():void { } } class ball extends Cluster_item { public var c:uint; public var r:uint; public var s:uint; public var xs:int; public var ys:int; function ball(arg_Cluster:Object, arg_stage:Stage, arg_x:int, arg_y:int, arg_r:uint, arg_c:uint, arg_s:uint) { Cluster = arg_Cluster; x = arg_x; y = arg_y; c = arg_c; r = arg_r; draw(); s = arg_s; xs = s; ys = s; addToCluster("ball"); arg_stage.addEventListener(Event.ENTER_FRAME, frame); } public override function beforeRemove():void { stage.removeEventListener(Event.ENTER_FRAME, frame); } public function draw():void { graphics.clear(); graphics.beginFill(c); graphics.drawCircle(0, 0, r); graphics.endFill(); } public function frame(e:Event):void { var o:Object; for(var tmp:String in Cluster["ball"]) { o = Cluster["ball"][tmp]; //if(r + o.r > Point.distance(new Point(x, y), new Point(o.x, o.y))) if(r + o.r > Math.sqrt(Math.pow(x - o.x, 2) + Math.pow(y - o.y, 2))) { if(x > o.x) { xs = s; o.xs = -o.s; } else if(x < o.x) { xs = -s; o.xs = o.s; } if(y > o.y) { ys = s; o.ys = -o.s; } else if(y < o.y) { ys = -s; o.ys = o.s; } } } if(x + r > stage.stageWidth) xs = -s; else if(x - r < 0) xs = s; if(y + r > stage.stageHeight) ys = -s; else if(y - r < 0) ys = s; x += xs; y += ys; } } Code Fullscreen Preview Fullscreen heckmeck frame name addChild stage Math.floor Object removeChild Math.pow bitmapData clear addEventListener drawCircle Math.sqrt endFill beginFill removeEventListener push draw Event.ENTER_FRAME stageWidth sort new page view favorite forked pv144 forked from: Bitmapのテスト forked:0 favorite:0lines:124 (diff:1) pv164 forked from: Bitmapのテスト nokura forked:0 favorite:0lines:124 (diff:1) pv134 forked from: Bitmapのテスト hacker_tougsh9g forked:0 favorite:0lines:124 (diff:1)