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. Partial RenderPartial Action RenderAction 区别和用法

    区别: 1.Partial 与 RenderPartial 两个方法性质基本一样,只是把一个静态用户控件给嵌入进来. 2.Partial 回传一堆html代码,直接写进到页面上@Html.Partia ...

  2. 004. 线程间操作无效: 从不是创建控件“textBox1”的线程访问它

    最简单的方法(不推荐): 在窗体构造函数中写Control.CheckForIllegalCrossThreadCalls =false; 为什么不推荐上面的方法: 为避免空间造成死锁, .net f ...

  3. linux包之procps之pmap命令

    名称:       pmap - report memory map of a process(查看进程的内存映像信息)用法       pmap [ -x | -d ] [ -q ] pids... ...

  4. 题目1049:字符串去特定字符——九度OJ

    题目1049:字符串去特定字符 http://ac.jobdu.com/problem.php?pid=1049 时间限制:1 秒 内存限制:32 兆 题目描述: 输入字符串s和字符c,要求去掉s中所 ...

  5. java.sql.SQLException: Io 异常: Connection reset

    当数据库连接池中的连接被创建而长时间不使用的情况下,该连接会自动回收并失效,但客户端并不知道,在进行数据库操作时仍然使用的是无效的数据库连接,这样,就导致客户端程序报“ java.sql.SQLExc ...

  6. comet4j文档

    Comet4J配置参数表 <!--Comet4J配置 --> <listener> <description>Comet4J容器侦听</description ...

  7. 在64位系统使用PLSQL Developer

    由于PLSQL Developer没有提供64位的,于是根据网上的资料做了一下整理,发上来 1.下载并安装Oracle 11g R2 64位,在服务器上安装时忽略硬件检测失败信息: 2.下载Oracl ...

  8. 每日学习心得:CustomValidator验证控件验证用户输入的字符长度、Linq 多字段分组统计、ASP.NET后台弹出confirm对话框,然后点击确定,执行一段代码

    2013-9-15 1.    CustomValidator验证控件验证用户输入的字符长度 在实际的开发中通常会遇到验证用户输入的字符长度的问题,通常的情况下,可以写一个js的脚本或者函数,在ASP ...

  9. cocoapods的安装及注意事项

    cocoapods是运行在ruby环境下的,在ruby环境的 ,像cocoapods这样的开源项目时放在放在rubygems服务器上面的,但国内访问https://rubygems.org/ 的时候会 ...

  10. nova分析(5)—— nova-conductor

    nova-conductor是nova-compute之上的一个服务,这个服务比较简单,主要封装了DB访问和动态迁移相关的代码.转来一篇文章看看它是如何工作的. 更新记录:1. 2013.4.19   ...