액션스크립트3.0으로 만든 RGB큐브.



(▼여기에 플래시가 삽입되어 있습니다)




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
import flash.display.Shape;
import flash.geom.Vector3D;
import flash.geom.Matrix3D;
import flash.events.MouseEvent;
 
var scale:int = 160;
var density:int = 10;
var densityCube:int = density*density*density;
var points:Vector.<Shape> = new Vector.<Shape>(densityCube);
var pointsPosition:Vector.<Vector3D> = new Vector.<Vector3D>(densityCube);
var centralPoint:Vector3D = new Vector3D(stage.stageWidth/2, stage.stageHeight/2, scale/2);
var angleSpd:Number = 0;
var mouseAngle:Number = 0;
var mouseDistance:Number = 0;
var mouseSin:Number = 0;
var mouseCos:Number = 1;
 
for(var i_z:int=0; i_z<density; i_z++) {
    for(var i_y:int=0; i_y<density; i_y++) {
        for(var i_x:int=0; i_x<density; i_x++) {
            var index:int = density*density*i_z+density*i_y+i_x;
            var color:uint = int(i_z/density*256)<<16|int(i_y/density*256)<<8|int(i_x/density*256);
            points[index] = new Shape();
            points[index].graphics.beginFill(color);
            points[index].graphics.drawRect(0,0,4,4);
            points[index].graphics.endFill();
             
            pointsPosition[index] = new Vector3D();
            pointsPosition[index].x = centralPoint.x-scale/2 + i_x*scale/(density-1);
            pointsPosition[index].y = centralPoint.y-scale/2 + i_y*scale/(density-1);
            pointsPosition[index].z = centralPoint.z-scale/2 + i_z*scale/(density-1);
             
            points[index].x = pointsPosition[index].x;
            points[index].y = pointsPosition[index].y;
            points[index].z = pointsPosition[index].z;
            addChild(points[index]);
        }
    }
}
 
 
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
function enterFrameHandler(evt:Event):void
{
    for(var index:int=0; index<densityCube; index++) {
        pointsPosition[index].x -= centralPoint.x;
        pointsPosition[index].y -= centralPoint.y;
        pointsPosition[index].z -= centralPoint.z;
         
        var old:Vector3D = new Vector3D(pointsPosition[index].x, pointsPosition[index].y, pointsPosition[index].z);
        pointsPosition[index].y = Math.cos(angleSpd*mouseSin)*old.y - Math.sin(angleSpd*mouseSin)*old.z;
        pointsPosition[index].z = Math.sin(angleSpd*mouseSin)*old.y + Math.cos(angleSpd*mouseSin)*old.z;
        old.x=pointsPosition[index].x; old.y=pointsPosition[index].y; old.z=pointsPosition[index].z;
        pointsPosition[index].x = Math.cos(angleSpd*mouseCos)*old.x - Math.sin(angleSpd*mouseCos)*old.z;
        pointsPosition[index].z = Math.sin(angleSpd*mouseCos)*old.x + Math.cos(angleSpd*mouseCos)*old.z;
     
        pointsPosition[index].x += centralPoint.x;
        pointsPosition[index].y += centralPoint.y;
        pointsPosition[index].z += centralPoint.z;
         
        points[index].x = pointsPosition[index].x;
        points[index].y = pointsPosition[index].y;
        points[index].z = pointsPosition[index].z;
    }
 
}
 
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
function mouseMoveHandler(evt:MouseEvent):void
{
    var dx:Number = stage.mouseX-stage.stageWidth/2;
    var dy:Number = stage.mouseY-stage.stageHeight/2;
    mouseDistance = Math.sqrt(dx*dx+dy*dy);
    mouseCos = dx/mouseDistance;
    mouseSin = dy/mouseDistance;
    angleSpd = mouseDistance/2000;
}






===========================================================================================





+ Recent posts