做了个简单的例子,S个宽W高H的矩形以R为半径围成一个圆柱绕X轴旋转。效果如图所示:
 代码如下:
- package
- {
- import flash.display.*;
- import flash.events.*;
- use namespace astro;
- public class Cylindrical extends Sprite
- {
- private var cylindrical:Sprite;
- private const S:int = 20; // 边数
- private const R:int = 50; // 半径
- private const W:int = 200; // 矩形长度
- private const H:int = 20; // 矩形宽度
- public function Cylindrical()
- {
- createCylindrical();
- addEventListener(Event.ENTER_FRAME, function(E:Event):void
- {
- cylindrical.astro::rotationX++;
- }
- );
- }
- private function createCylindrical():void
- {
- cylindrical = new Sprite;
- var s:Sprite;
- var c:Number = 360 / S;
- var a:Number;
- for(var i:int = 0; i <= S; i++){
- s = new Sprite;
- s.graphics.lineStyle(1, 0xffffff, 1);
- s.graphics.beginFill(0xffffff * Math.random(), .8);
- s.graphics.drawRect(0, 0, W, H);
- a = i * c / 180 * Math.PI;
- s.x = 0;
- s.y = R * Math.cos(a);
- s.astro::z = R * Math.sin(a);
- s.astro::rotationX = i * c;
- cylindrical.addChild(s);
- }
- cylindrical.x = 150;
- cylindrical.y = 200;
- addChild(cylindrical);
- }
- }
- }
其中命名空间astro如下:
- package
- {
- public namespace astro = 'http://www.adobe.com/2008/actionscript/Flash10/';
- }
|