package
{
import flash.display.Sprite;
import flash.events.Event; /**
* @author Frost.Yen
* @E-mail 871979853@qq.com
* @create 2015-9-9 下午4:47:50
*
*/
[SWF(width="1024",height="1024",frameRate="3")]
public class DrawStar extends Sprite
{
public function DrawStar()
{
initViews();
initEventListeners();
}
private function initViews():void
{
draw();
}
private function initEventListeners():void
{
this.addEventListener(Event.ENTER_FRAME,onFresh);
}
private function onFresh(e:Event):void
{
this.removeChildren();
draw();
}
private function draw():void
{
for(var i:int=0;i<64;i++){
var star:Star = new Star(Math.random()*10+2,50,20,Math.random()*255-Math.random()*0xffffff,Math.random()*0xffffff-Math.random()*255,true);
star.x = i%8*100+100;
star.y = Math.floor(i/8)*100+100;
this.addChild(star);
}
}
}
}
import flash.display.Sprite; class Star extends Sprite
{
private var _b:Boolean;
private var _x:Number;
private var _y:Number;
/**
*
* @param len 星形边数
* @param radius1 五角星中心点离较远顶点的距离(可看作五角星外接圆的半径)
* @param radius2 五角星中心点离较近顶点的距离(可看作五角星内接圆的半径)
* @param lineColor 线条颜色
* @param fillColor 填充颜色
* @param isFill 是否填充
*/
public function Star(len:int=5,radius1:Number=50,radius2:Number=20,lineColor:uint=0xff0000,fillColor:uint=0x00ffff,isFill:Boolean=false){
if(len<=1){
trace("星形边数至少为2");
return;
}
this.graphics.lineStyle(1,lineColor);
if(isFill){
this.graphics.beginFill(fillColor)
}
this.graphics.moveTo(radius2,0);
for(var i:int = 1;i<=len*2;i++){
_b?[_x=radius2*Math.cos(i*Math.PI*2/(len*2)),_y=radius2*Math.sin(i*Math.PI*2/(len*2))]:[_x=radius1*Math.cos(i*Math.PI*2/(len*2)),_y=radius1*Math.sin(i*Math.PI*2/(len*2))];
this.graphics.lineTo(_x,_y);
_b=!_b;
}
if(len%2!=0){
this.rotation = 90;
}
}
}

[ActionScript 3.0] AS3 绘制星形的更多相关文章

  1. [ActionScript 3.0] AS3 绘制12面体

    package { import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; im ...

  2. [ActionScript 3.0] AS3 3D星形贴图

    package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.MovieCl ...

  3. [ActionScript 3.0] AS3 绘制正四面体(线条)

    package { import flash.display.MovieClip; import flash.display.Sprite; import flash.events.Event; im ...

  4. [ActionScript 3.0] AS3 绘制正八面体(线条)

    分析: 将八面体置于3D坐标系中,其中心的坐标位于原点(0,0,0),让八面体的六个顶点恰好位于3D坐标系的x轴.y轴和z轴上,则从八面体的中心到这六个顶点的距离是相等的.我们可以假设这个距离为r,则 ...

  5. [ActionScript 3.0] AS3 绘制正二十面体(线条)

    分析: 正二十面体共有12个顶点.30条棱,其20个面都是正三角形.每条棱所对应的弧度值为1.1071487177940904弧度,这个弧度值可通过求Math.sqrt(5)/5的反余弦值求得.正二十 ...

  6. [ActionScript 3.0] AS3 绘制立方体

    package { import flash.display.Sprite; import flash.events.Event; import flash.geom.Vector3D; import ...

  7. [ActionScript 3.0] AS3 绘制任意三角形任意顶点到对边的高

    注:顶点坐标可以点击 package { import flash.display.Shape; import flash.display.Sprite; import flash.events.Mo ...

  8. [ActionScript 3.0] as3处理xml的功能和遍历节点

    as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象 ...

  9. [ActionScript 3.0] AS3.0 动态加载显示内容

    可以将下列任何外部显示资源加载到 ActionScript 3.0 应用程序中: 在 ActionScript 3.0 中创作的 SWF 文件 — 此文件可以是 Sprite.MovieClip 或扩 ...

随机推荐

  1. EDIUS分别输出视频和音频的教程

    使用EDIUS剪辑好视频之后渲染输出文件时,为什么视频和音频分别出,而不是一起呢?这个问题很可能会让一些新手困惑不已,到底是什么原因呢?又要如何设置才能让输出的文件视音频一体呢?下面,小编将来和大家探 ...

  2. winform 调用http 通过代理出现的一系列问题

    如果遇到以上问题,请拷贝以下代码到你的桌面应用程序的app.config 文件中 <system.net> <defaultProxy enabled="false&quo ...

  3. Android ListView 第一次设置Adapter时候getView调用多次

    之前遇到这个奇怪现象,记录一下: 使用Listview并设置Adapter时, 会回调多次getView,比如我有4个items,按理说getView应该是调用一次(打出4个log),结果回调有4次( ...

  4. CSS3之Flexbox布局

    CSS3为我们提供了一种可伸缩的灵活的web页面布局方式-flexbox布局,它具有很强大的功能,可以很轻松实现很多复杂布局,在它出现之前,我们经常使用的布局方式是浮动或者固定宽度+百分比来进行布局, ...

  5. MySql之on duplicate key update详解

    在我们的日常开发中,你是否遇到过这种情景:查看某条记录是否存在,不存在的话创建一条新记录,存在的话更新某些字段.你的处理方式是不是就是按照下面这样? $result = mysql_query('se ...

  6. HTML5 javascript修改canvas的大小

    方法1: 设定固定的值,这种方式跟在html中设定canvas的值没有什么区别: window.onload = function(){ canvas.height = 100; canvas.wid ...

  7. Neutron分析(6)—— neutron-openvswitch-agent

    neutron-openvswitch-agent代码分析 neutron.plugins.openvswitch.agent.ovs_neutron_agent:main # init ovs fi ...

  8. android 插件化开发 开源项目列表

    开源的插件化框架 Qihoo360/DroidPlugin CtripMobile/DynamicAPK mmin18/AndroidDynamicLoader singwhatiwanna/dyna ...

  9. lwip初始化过程

    首先应该看下源码包中的doc/rawapi.txt,这篇文档中介绍了初始化流程. 初始化过程的前半部分主要针对lwip的内存管理和各个协议层,在src/core/init.c中有一个lwip_init ...

  10. Python 字典和列表的对比应用

    Q:将下列格式的txt文件,打印出该选手的3个最快跑步时间 james2.txt =>“James Lee,2002-3-14,2-34,3:21,2.34,2.45,3.01,2:01,2:0 ...