▼Wonderfl
▼ActionScript AS3(FP10)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
/* なんとなく。キューブが回転する奴。 10年くらい前に3Dソフトでとりあえずこんな感じの ものを作ったような。 */ package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.DisplayObjectContainer; import flash.display.Sprite; import flash.events.Event; import flash.geom.Matrix; import flash.geom.PerspectiveProjection; import flash.geom.Point; import flash.geom.Vector3D; [SWF(backgroundColor="0xF8F8F8")] public class Main extends Sprite { private var _box:Array = []; private var _canvas:Sprite; private var _bitmapData:BitmapData; private var _bitmap:Bitmap; public function Main() { //stage.scaleMode = "noScale"; _bitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false,0xF8F8F8); _bitmap = new Bitmap(_bitmapData,"auto",true); this.addChild(_bitmap) _canvas = new Sprite(); stage.transform.perspectiveProjection = new PerspectiveProjection(); stage.transform.perspectiveProjection.projectionCenter = new Point(stage.stageWidth/2,stage.stageHeight/2); var n:int = 10; for (var i:int = 0; i < n; i++) { _box[i] = new Box(); _box[i].x = stage.stageWidth/2-70*Math.sin(2*Math.PI*i/n)+Math.random()*40-20; _box[i].y = stage.stageHeight/2-70*Math.cos(2*Math.PI*i/n)+Math.random()*40-20; _box[i].z = 300*i-200; _box[i].rotationZ = 5*i; _canvas.addChild(_box[i]); } this.addEventListener(Event.ENTER_FRAME,onEnter); } private function onEnter(event:Event):void{ var n:int = _box.length; for (var i:int = 0; i < n; i++) { _box[i].rotationX ++; var z:Number = _box[i].z-1; _box[i].z = 2500-(2500-z)%3000; _box[i].rotationY += 0.3; _box[i].rotationZ += 0.005; _box[i].alpha = Math.min(1,(500+z)/250) } zSort(_canvas); _bitmapData.lock(); var bd:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false,0xF8F8F8); bd.draw(_canvas); _bitmapData.draw(bd,new Matrix(-1,0,0,-1,stage.stageWidth,stage.stageHeight)); _bitmapData.draw(bd,null,null,"darken"); _bitmapData.unlock(); } private function zSort(target:DisplayObjectContainer):void { var n:int = target.numChildren; var array:Array = []; var reference:Array = []; for (var i:int = 0; i < n; i++) { var poz:Vector3D = target.getChildAt(i).transform.getRelativeMatrix3D(stage).position; var point:Point = stage.transform.perspectiveProjection.projectionCenter; array[i] = poz.subtract(new Vector3D(point.x,point.y,-stage.transform.perspectiveProjection.focalLength)).length; reference[i] = target.getChildAt(i); } var temp:Array = array.sort(Array.NUMERIC | Array.RETURNINDEXEDARRAY); for (i = 0; i < n; i++) { target.setChildIndex(reference[temp[i]],0); if(reference[temp[i]].numChildren > 1){ zSort(reference[temp[i]]); } } } } } import flash.display.Sprite; class Box extends Sprite{ public function Box(){ var colors:Array = [0x000000,0x111111,0x222222,0x333333,0x444444,0x555555]; var ran:int = Math.floor(Math.random()*6); for (var i:int = 0; i < 6; i++) { var sp:Sprite = new Sprite(); sp.graphics.beginFill(colors[(i+ran)%6],1); sp.graphics.drawRect(-50,-50,100,100); sp.graphics.endFill(); switch (i) { case 0: sp.z = -50; break; case 1: sp.z = 50; break; case 2: sp.rotationX = 90; sp.y = 50; break; case 3: sp.rotationX = 90; sp.y = -50; break; case 4: sp.rotationY = 90; sp.x = -50; break; case 5: sp.rotationY = 90; sp.x = 50; break; } this.addChild(sp); } } } |