Cube
/**
* Copyright quail24eggs ( http://wonderfl.net/user/quail24eggs )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gaKc
*/
// キューブ
package
{
import flash.display.Sprite;
import flash.events.Event;
public class Main extends Sprite
{
public function Main():void
{
var nUnit:Number = 200;//格子定数
var sq1:Sprite = new Sprite();
var sq2:Sprite = new Sprite();
var sq3:Sprite = new Sprite();
var sq4:Sprite = new Sprite();
var sq5:Sprite = new Sprite();
var sq6:Sprite = new Sprite();
mySquare(sq1, nUnit);
mySquare(sq2, nUnit);
mySquare(sq3, nUnit);
mySquare(sq4, nUnit);
mySquare(sq5, nUnit);
mySquare(sq6, nUnit);
function mySquare(sqName:Sprite, m:Number):void //Sprite のプロパティ設定
{
sqName.graphics.beginFill(0xFFFFFF* Math.random());
sqName.x = m;
sqName.y = m;
sqName.alpha = 0.2;
sqName.graphics.drawRect(0, 0, m, m);
}
var nX:Number = stage.stageWidth / 2;
var nY:Number = stage.stageHeight / 2;
var nDec:Number = 1/80;//減速率
var mySprite:Sprite = new Sprite();
this.addChild(mySprite);
mySprite.x = nX;
mySprite.y = nY;//mySprite を stage 中央へ
mySprite.addChild(sq1);
mySprite.addChild(sq2);
mySprite.addChild(sq3);
mySprite.addChild(sq4);
mySprite.addChild(sq5);
mySprite.addChild(sq6);
sq1.x = -nUnit / 2;
sq1.y = -nUnit / 2;
sq1.z = -nUnit / 2;
sq2.x = nUnit / 2;
sq2.y = -nUnit / 2;
sq2.z = -nUnit / 2;
sq3.x = nUnit / 2;
sq3.y = -nUnit / 2;
sq3.z = nUnit / 2;
sq4.x = -nUnit / 2;
sq4.y = -nUnit / 2;
sq4.z = nUnit / 2;
sq5.x = -nUnit / 2;
sq5.y = -nUnit / 2;
sq5.z = -nUnit / 2;
sq6.x = -nUnit / 2;
sq6.y = nUnit / 2;
sq6.z = -nUnit / 2;
sq2.rotationY = -90;
sq3.rotationY = -180;
sq4.rotationY = -270;
sq5.rotationX = 90;
sq6.rotationX = 90;
addEventListener(Event.ENTER_FRAME,xyRotate);
function xyRotate(obj:Event):void
{
var nRotX:Number = mySprite.rotationX;
nRotX -= (mouseY - nY) * nDec; //The Variable nDec is defined in the line 34.
nRotX = getDegree(nRotX);
mySprite.rotationX = nRotX;
var nRotY:Number = mySprite.rotationY;
nRotY += (mouseX - nX) * nDec;
nRotY = getDegree(nRotY);
mySprite.rotationY = nRotY;
}
function getDegree(n:Number):Number
{
n += 180;
n %= 360;
n += 360;
n %= 360;
n -= 180;
return n;
}
}
}
}