ActionScript 3 改进的Spiderweb ActionScript3.0类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 改进的Spiderweb ActionScript3.0类相关的知识,希望对你有一定的参考价值。
package com.blogspot.flanture.drawing
{
// Spiderweb drawing class
// author: http://flanture.blogspot.com
// version: 1.0
// February 2010
import flash.display.Sprite;
import flash.geom.Point;
public class spiderweb extends Sprite
{
private var _circles:uint; // number of concentric circles
private var _nods:uint; // number of nods on each circle
private var _df:Number; // circles distance factor
private var _fr:Number; // smallest circle radius
private var _sf:Number; // stretch factor
public function spiderweb(circles:uint, nods:uint, fr:Number, df:Number, sf:Number)
{
_circles = circles;
_nods = nods;
_fr = fr;
_df = df;
_sf = sf;
init();
}
private function init():void
{
var cx = 0;
var cy = 0;
var coords:Array = new Array();
var controls:Array = new Array();
var angle:Number;
var controlAngle:Number;
var currR:Number;
var angleStep:Number = 360 / _nods;
currR = _fr;
for(var k:uint = 0; k < _circles; k++)
{
currR += currR * _df;
for (var i:uint = 0; i < _nods; i++)
{
angle = angleStep * (i + 1);
controlAngle = angle - angleStep / 2;
controlAngle = controlAngle * Math.PI / 180;
angle = angle * Math.PI / 180;
var x1:Number = trim(currR * Math.cos(angle));
var y1:Number = trim(currR * Math.sin(angle));
var tx:Number = trim(currR * Math.cos(controlAngle));
var ty:Number = trim(currR * Math.sin(controlAngle));
tx *= _sf;
ty *= _sf;
var cpoint:Point = new Point(tx, ty);
controls.push(cpoint);
var point:Point = new Point(x1, y1);
coords.push(point);
}
drawStraights(coords);
drawCurves(coords, controls);
coords.splice(0, _nods);
controls.splice(0, _nods);
}
}
private function trim(num:Number):Number
{
var nstr:int = int(num*100);
return Number(nstr / 100);
}
private function drawStraights(array):void
{
this.graphics.lineStyle(1, 0xffffff);
this.graphics.moveTo(0,0);
for (var i:uint = 0; i < array.length; i++)
{
this.graphics.lineTo(array[i].x, array[i].y);
this.graphics.moveTo(0,0);
}
}
private function drawCurves(arrayA, arrayB):void
{
this.graphics.lineStyle(2, 0xffffff);
for (var j:uint = 0; j < arrayA.length-1; j++)
{
this.graphics.moveTo(0,0);
this.graphics.moveTo(arrayA[j].x, arrayA[j].y);
this.graphics.curveTo(arrayB[j+1].x, arrayB[j+1].y, arrayA[j+1].x, arrayA[j+1].y);
this.graphics.moveTo(0,0);
}
this.graphics.moveTo(arrayA[arrayA.length-1].x, arrayA[arrayA.length-1].y);
this.graphics.curveTo(arrayB[0].x, arrayB[0].y, arrayA[0].x, arrayA[0].y);
}
}
}
以上是关于ActionScript 3 改进的Spiderweb ActionScript3.0类的主要内容,如果未能解决你的问题,请参考以下文章
Actionscript 3:预渲染类实例以提高性能
Flash / Actionscript CPU 分析器
ActionScript 3 ActionScript 3中的反射
ActionScript 3 actionscript 3简单的拖放
ActionScript 3 使用Actionscript 3的onEnterFrame事件
ActionScript 3 使用ActionScript 3暂停框架