[AS3]AS3画正多边形源代码示例
[AS3]AS3画正多边形源代码示例,绘制一个有填充颜色的正五边形,将多边形对象添加到舞台
调用方法:
- import Polygon; //引用脚本
- var my_poly:Polygon=new Polygon(); //实例化一个多边形对象
- /*
- *drawPolygon(radius:int,segments:int,centerX:Number,
centerY:Number,tint:uint,line:int,rotating:Number,fillColor:uint=0)- *radius: 边长, px为单位,正整数,
- *segments:边的个数,正整数
- *centerX: 中心点x坐标
- *centerY: 中心点y坐标
- *tint: 边颜色, 16进制数字 例如:0xFF0000 红色
- *line: 边线宽度,px为单位
- *rotating: 多边形旋转角度,
- *fillColor: 填充颜色,16进制数字 不提供值时不填充。
- *
- */
- my_poly.drawPolygon(100,7,300,200,0xFF0000,1,0);
//CuPlayer.com绘制一个无填充颜色的正七边形- my_poly.drawPolygon(100,5,300,200,0xFF0000,1,0,0x00FF00);
//CuPlayer.com绘制一个有填充颜色的正五边形- addChild(my_poly); //将多边形对象添加到舞台
- package
- {
- import flash.display.MovieClip;
- import flash.events.Event;
- public class Polygon extends MovieClip
- {
- //CuPlayer.com PROPERTIES
- private var points:Array;
- private var id:int;
- private var ratio:Number;
- private var top:Number;
- //CuPlayer.com CONSTRUCTOR
- public function Polygon()
- {
- addEventListener(Event.ADDED_TO_STAGE,init);
- }
- private function init(evt:Event):void
- {
- removeEventListener(Event.ADDED_TO_STAGE,init);
- stage.frameRate=30;
- }
- //CuPlayer.com METHODS
- public function drawPolygon(radius:int,segments:int,
centerX:Number,centerY:Number,tint:uint,line:int,rotating:Number,fillColor:uint=0):void- {
- id=0;
- points=new Array();
- ratio=360/segments;
- top=centerY-radius;
- if(fillColor!=0)
- graphics.beginFill(fillColor);
- for(var i:int=rotating;i<=360+rotating;i+=ratio)
- {
- var xx:Number=centerX+Math.sin(radians(i))*radius;
- var yy:Number=top+(radius-Math.cos(radians(i))*radius);
- points[id]=new Array(xx,yy);
- switch(id)
- {
- case 0:
- break;
- case 1:
- graphics.lineStyle(line,tint,1);
- graphics.moveTo(points[id-1][0],points[id-1][1]);
- graphics.lineTo(points[id][0],points[id][1]);
- break;
- default:
- graphics.lineTo(points[id][0],points[id][1]);
- //drawing(points[id-1][0],points[id-1][1],points[id][0],points[id][1],tint,line);
- }
- id++;
- }
- if(fillColor!=0)
- graphics.endFill();
- id=0;
- }
- private function radians(n:Number):Number
- {
- return(Math.PI/180*n);
- }
- }
- }
- //脚本代码结束
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...