Forked from: Yaski's 3D cube with motion blur diff:8 forked from: 3D cube with motion blur hacker_laip9.. forked:1favorite:0lines:92license : All rights reserved modified : 2008-12-24 08:11:17 Embed Tweet // forked from Yaski's 3D cube with motion blur // forked from ll_koba_ll's 3D cube // write as3 code here.. package { import flash.display.*; import flash.text.*; import flash.events.*; import flash.geom.*; [SWF(frameRate="1000", backgroundColor="#011000")] public class Cube extends Sprite { private var sp:Sprite; private var canvas:Sprite = new Sprite(); private var faceArray:Array; private const CUBE_SCALE:int = 50 private var dirX:Boolean = false; private var dirY:Boolean = false; private var dirZ:Boolean = false; private var bmp:Bitmap; private var fadeTransform:ColorTransform = new ColorTransform(0, 0.7, 0); public function Cube() { init(); bmp = new Bitmap(new BitmapData(300, 300, false, 0x0)); bmp.smoothing = true; bmp.width = stage.stageWidth; bmp.height = stage.stageHeight; addChild(bmp); } private function init():void { createCubeFace(); addEventListener(Event.ENTER_FRAME, function(e:Event):void { sp.rotationY += 1; sp.rotationX += 2; sp.x = (dirX) ? sp.x + 8 : sp.x - 1; sp.y = (dirY) ? sp.y + 6 : sp.y - 6; sp.z = (dirZ) ? sp.z + 2 : sp.z - 2; if (sp.x >= 300 || sp.x <= 20) {dirX = !dirX}; if (sp.y >= 250 || sp.y <= 0) {dirY = !dirY}; if (sp.z >= 300 || sp.z <= 10) {dirZ = !dirZ}; bmp.bitmapData.colorTransform(bmp.bitmapData.rect, fadeTransform); bmp.bitmapData.draw(canvas); }); } private function createCubeFace():void { sp = new Sprite(); canvas.addChild(sp); sp.x = 200; sp.y = 200; var s:Sprite; faceArray = new Array(); function createFace(c:uint):Sprite { var s:Sprite = new Sprite(); drawRect(s, c); sp.addChild(s); return s } // 背面 s = createFace(0xff0000); s.z = CUBE_SCALE/2; var t:TextField = new TextField(); s.addChild(t); t.text = "AS 3 is COOL!!!"; t.autoSize = TextFieldAutoSize.LEFT; t.setTextFormat(new TextFormat("_ゴシック", 15, 0xFF0000)); t.x = -10 t.y = -20 // 左 s = createFace(0x0000ff); s.rotationY = 90; s.x = -CUBE_SCALE/2; // 右 s = createFace(0x00ff00); s.rotationY = 90; s.x = CUBE_SCALE/2; // 上 s = createFace(0xffff00); s.rotationX = 90; s.y = -CUBE_SCALE/2; // 下 s = createFace(0x00ffff); s.rotationX = 90; s.y = CUBE_SCALE/2; // 前面 s = createFace(0xaaaaaa); s.z = -CUBE_SCALE/1; t = new TextField(); s.addChild(t); t.text = "Updated by Яски"; t.autoSize = TextFieldAutoSize.LEFT; t.setTextFormat(new TextFormat("_ゴシック", 15, 0xFF)); t.x = -50 t.y = -20 } private function drawRect(s:Sprite, c:uint):void { var g:Graphics = s.graphics; g.lineStyle(2, 0xFF00); g.beginFill(c, 1); // z sort してないから塗りは消しておく g.drawRect(-CUBE_SCALE/2, -CUBE_SCALE/2, CUBE_SCALE, CUBE_SCALE); g.endFill(); } } } Code Fullscreen Preview Fullscreen setTextFormat smoothing drawRect rotationY rotationX Boolean graphics TextFieldAutoSize.LEFT beginFill autoSize endFill addEventListener text colorTransform ColorTransform height width TextFormat draw addChild sort new page view favorite forked pv414 forked from: forked from: 3D c.. hacker_laip932_ forked:1 favorite:0lines:92 (diff:8)