应用思考-教育技术论坛
标题:
勾股树
[打印本页]
作者:
东拼西筹
时间:
2012-6-20 20:30
标题:
勾股树
本帖最后由 东拼西筹 于 2012-6-20 20:33 编辑
勾股定理
http://files.cnblogs.com/ddw1997/testVector2D.swf
作者:
etthink
时间:
2012-6-21 07:17
最好能介绍个实现原理和过程...
作者:
东拼西筹
时间:
2012-6-21 16:05
递归的简单实现
package
{
import com.FPS;
import com.Vector2D;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import com.Rect;
import com.ColorUtil;
import flash.events.MouseEvent;
import flash.geom.Point;
/**
* ...
* @author ddw1997
*/
[SWF(width="800",height="600",frameRate="24",backgroundColor="#999999")]
public class RectTree extends Sprite
{
private var rectW:int;
private var level:int;
private var speed:Number;
private var percent:Number;
private var contain:Sprite;
private var rect0:Rect;
private var isLoop:Boolean;
public function RectTree()
{
if (stage)
init();
else
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
rectW = 100;
level = 8;
percent = 0.3;
speed = 0.008;
contain = new Sprite();
addChild(contain );
contain .x = 300;
contain.y = 500;
var fps:FPS = new FPS();
addChild(fps);
isLoop = true;
addEventListener(Event.ENTER_FRAME, loop);
stage.addEventListener(MouseEvent.CLICK, pause);
}
private function pause(e:MouseEvent):void
{
if (isLoop) removeEventListener(Event.ENTER_FRAME, loop);
else addEventListener(Event.ENTER_FRAME, loop);
isLoop = !isLoop;
}
private function loop(e:Event):void
{
contain.graphics.clear();
percent += speed;
if (percent > 1 || percent < 0)
{
speed *= -1;
}
percent = Math.min(1, Math.max(0, percent ));
rect0 = new Rect(new Point(0, 0), new Point(rectW, 0), new Point(rectW, rectW), new Point(0, rectW), percent, 0x992200, contain.graphics);
drawRect(rect0, 1);
}
private function drawRect(rect:Rect,n:int):void
{
if (n > level) return;
else
{
n = n + 1;
drawRect(getNextRect(rect.pointA,rect.percentPoint,rect.pointB,ColorUtil.getColor(n,level*3),percent,contain.graphics),n);
drawRect(getNextRect(rect.percentPoint,rect.pointB,rect.pointA,ColorUtil.getColor(n,level*3),percent,contain.graphics),n);
}
}
private function getNextRect(p1:Point,p2:Point,tagPoint:Point,col:uint,percent:Number,g:Graphics):Rect
{
var v_12:Vector2D = new Vector2D();
v_12.updateVector(true, p1, p2);
v_12 = v_12.rotate( -90);
var pointA:Point = v_12.endPoint.clone();
v_12.startPoint = p2;
var pointB:Point = v_12.endPoint.clone();
return new Rect(pointA,pointB,p2,p1,percent,col,g)
}
}
}
复制代码
作者:
牛蛙
时间:
2012-6-21 23:37
对实现原理毫无头绪
作者:
Suqh
时间:
2012-7-3 15:36
好厉害
欢迎光临 应用思考-教育技术论坛 (http://etthink.com/)
Powered by Discuz! X3.4