Plant a tree and watch it grow
by Stanislav Kalashnik
JavaScript
var leaf = function(food, branchDirection){
this.food = food || 0;
this.branchDirection = branchDirection;
this.char = 'o';
this.getHtml = function(){
var color = "#00FF00";
var bgColor = "#00BBEE";
return "<span style=\"color: " + color + "; background-color: " + bgColor + "\">" + this.char + "</span>";
};
};
var branch = function(food, direction){
var directionChars = ["_", "\\", "|", "/"];
this.food = food || 0;
this.char = directionChars[direction];
this.direction = direction;
this.child_branches = [];
this.getPossibleDirections = function(){
if(this.direction === 0)
{
return [
[-1, 0, [0,1,2]],
[+1, 0, [2,3,0]]
];
}
if(this.direction == 1)
{
return [
[-1, +1, [0,1,2]],
[0, +1, [3]]
];
}
if(this.direction == 2){
return [
[-1, +1, [0,1]],
[0, +1, [2]],
[+1, +1, [3,0]]
];
}
if(this.direction == 3){
return [
[+1 ,+1 , [0,2,3]],
[0 ,+1 , [1]]
];
}
};
this.getHtml = function(){
var color = "brown";
var bgColor = "#00BBEE";
return "<span style=\"color: " + color + "; background-color: " + bgColor + "\">" + this.char + "</span>";
};
};
var froot = function(food){
this.char = "O";
this.food = food || 0;
this.getHtml = function(){
var color = "#FF0000";
var bgColor = "#00BBEE";
return "<span style=\"color: " + color + "; background-color: " + bgColor + "\">" + this.char + "</span>";
};
};
var flower = function(food){
this.char = "@";
this.food = food || 0;
this.getHtml = function(){
var color = "#FFFF00";
var bgColor = "#00BBEE";
return "<span style=\"color: " + color + "; background-color: " + bgColor + "\">" + this.char + "</span>";
};
};
var ground = function(){
this.char = "_";
this.getHtml = function(){
var color = "black";
var bgColor = "#00BBEE";
return "<span style=\"color: " + color + "; background-color: " + bgColor + "\">" + this.char +...