In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

particleの回転

Get Adobe Flash player
by gaziya 10 Nov 2011
    Embed
/**
 * Copyright gaziya ( http://wonderfl.net/user/gaziya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1LzT
 */

// forked from gaziya's forked from: Matrix3Dのテスト
// forked from gaziya's Matrix3Dのテスト
package {
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.geom.PerspectiveProjection
    import flash.geom.Matrix3D;
    import flash.events.Event
    import flash.geom.Vector3D
    import flash.geom.Utils3D
    import flash.display.Sprite
    [SWF(width=465,height=465,frameRate=30)]
    
    public class FlashTest extends Sprite {
        public function FlashTest() {
            var number:int = 10000
            var length:Number = 1//200           
            
            var points:Vector.<Vector3D> = new Vector.<Vector3D>
            var n:int = number
            while(n--) {
                var vector:Vector3D = new Vector3D
                vector.x = Math.sqrt(Math.random()) * length
                var matrix:Matrix3D = new Matrix3D
                //matrix.appendRotation(Math.random()*360, Vector3D.X_AXIS)
                matrix.appendRotation(Math.random()*360, Vector3D.Y_AXIS)
                matrix.appendRotation(Math.random()*360, Vector3D.Z_AXIS)
                points.push(matrix.transformVector(vector))
            }                  
            
                    
            var canvas:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,false,0x0)
            addChild(new Bitmap(canvas))
            var theta:Number = 0
            var axis:Vector3D = new Vector3D(1,-2,0)                       
            var projection:PerspectiveProjection = new PerspectiveProjection()            
            var proj_matrix:Matrix3D = projection.toMatrix3D()          
           
            addEventListener(Event.ENTER_FRAME, loop)
            function loop(e:Event):void {
                theta += 1
                theta %= 360
                var matrix:Matrix3D = new Matrix3D()                
                matrix.appendRotation(theta,axis) 
                matrix.appendTranslation(0,0,length*3)   
                canvas.lock()
                canvas.fillRect(canvas.rect, 0x0)    
                var i:int = number
                while (i--){                
                    var p_point:Vector3D = Utils3D.projectVector(proj_matrix, matrix.transformVector(points[i]))               
                    canvas.setPixel(p_point.x+stage.stageWidth/2,p_point.y+stage.stageHeight/2,0xffffff)                    
                }
                canvas.unlock()  
            }    
        }
    }
}