In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Y Combinator Tree

coppieeeさんの書き方を使ってみた
http://twitter.com/coppieee/status/4940999170
※ 表現はmakc3dさんのものと変わりません
@author clockmaker

arguments.calleeを使わずに、Yコンビネータを使って再起したバージョン。
Yコンビネータ イミフ!
@see http://d.hatena.ne.jp/amachang/20080124/1201199469
@author coppieee
Get Adobe Flash player
by coppieee 16 Nov 2009
// forked from clockmaker's 再帰関数
// forked from makc3d's Random Green Tree (smaller flowers)
// forked from makc3d's Random Green Tree
package {
    import flash.display.Sprite;
	import flash.geom.Point;
    /**
    * coppieeeさんの書き方を使ってみた
    * http://twitter.com/coppieee/status/4940999170
    * ※ 表現はmakc3dさんのものと変わりません
	* @author clockmaker
    */
	
	/**
	 * arguments.calleeを使わずに、Yコンビネータを使って再起したバージョン。
	 * Yコンビネータ イミフ!
	 * @see http://d.hatena.ne.jp/amachang/20080124/1201199469
	 * @author coppieee
	 */
    public class Main extends Sprite {
        
        public function Main(){
            (function(Y:Function):Function {
				return Y(function(fact:Function):Function {
					return function (v:TreeValue):void{
						var dest:Point = v.createDest();
						var color:int = v.level == 0 && Math.random() < 0.5 ? 0xF0007 : v.cf;
						graphics.lineStyle(1 + 5 / (v.level-v.maxLevel), color * (v.maxLevel-v.level));
						graphics.moveTo(v.x, v.y);
						graphics.lineTo(dest.x, dest.y);
					
						if (v.level > 0){
							for (var i:int = 0; i < 3;i++ ){
								fact(v.next(dest));
							}
						}
					}
				})(TreeValue.create(stage.stageWidth / 2, stage.stageHeight, 90, -90, 0xF00,10,10))
				
			})(function(f:Function):Function {
				return (function(g:Function):Function {
					return function(m:TreeValue):void {
						f(g(g))(m);
					}
				})(function(g:Function):Function {
					return function(m:TreeValue):void {
						f(g(g))(m);
					};
				});
			});
			
			//Yコンビネータを使わなかったバージョン
			//(function (v:TreeValue):void{
				//var dest:Point = v.createDest();
				//var color:int = v.level == 0 && Math.random() < 0.5 ? 0xF0007 : v.cf;
				//graphics.lineStyle(1 + 5 / (v.level-v.maxLevel), color * (v.maxLevel-v.level));
				//graphics.moveTo(v.x, v.y);
				//graphics.lineTo(dest.x, dest.y);
				//
				//if (v.level > 0){
					//for (var i:int = 0; i < 3;i++ ){
						//arguments.callee(v.next(dest));
					//}
				//}
			//})(TreeValue.create(stage.stageWidth / 2, stage.stageHeight, 90, -90, 0xF00,10,10));
        }
    }
}
import flash.geom.Point;
class TreeValue
{
	public static function create(x:Number, y:Number, length:Number, angle:Number, cf:int, level:int, maxLevel:int):TreeValue {
		var v:TreeValue = new TreeValue();
		v.x  = x;
		v.y = y;
		v.length = length;
		v.angle = angle;
		v.cf = cf;
		v.level = level;
		v.maxLevel = maxLevel;
		return v;
	}
	public var x:Number;
	public var y:Number;
	public var length:Number;
	public var angle:Number;
	public var cf:int;
	public var level:int;
	public var maxLevel:int;
	
	public function createDest():Point { return new Point(
		x + length * Math.cos(angle * (Math.PI / 180)),
		y + length * Math.sin(angle * (Math.PI / 180)));
	}
	public function next(dest:Point):TreeValue {
		var v:TreeValue = new TreeValue();
		v.x = dest.x;
		v.y = dest.y;
		v.length = length * ( 1 + 3 * Math.random()) * 0.25;
		v.angle = angle + 60 * (Math.random() * 2 -1);
		v.cf = cf;
		v.level = level - 1;
		v.maxLevel = maxLevel;
		return v;
	}
}