// one way
ctx.fillStyle = "hsl(23, 50%, 100%)";
// probably more realistic
ctx.fillStyle = "hsl(" + hue + ", " + saturation + "%, ", + light +"%)";
var cellvalue = {'hue': 0, 'saturation': 100, 'light': 50, 'age': -1};
var names=["red","green", "blue"]
this.data = new Array(this.width);
for(var x =0; x < this.width; x++) {
this.data[x] = new Array(this.height);
for(y =0; y < this.height;y++) {
this.data[x][y] = {'hue': 0, 'saturation': 0, 'light': 100, 'age': -1}
}
}
Redisplay: function() {
var color, x,y;
this.Clear();
for(x =0; x < this.width; x++) {
for(y=0; y < this.height;y++) {
// only draw cells age 0 or older
if (this.data[x][y].age >= 0) {
color = "hsl(" + this.data[x][y].hue + ', '
+ this.data[x][y].saturation + '%, '
+ this.data[x][y].light + '%)'
this.ctx.fillStyle = color
this.ctx.fillRect(x,y,2,2);
}
}
}
return;
},
BlankArray: function() {
var x,y;
for(x =0; x < this.width; x++) {
for(y=0; y < this.height;y++) {
this.data[x][y] = {'hue': 0,
'saturation': 0,
'light': 50, 'age': -1}
}
}
},
NewPattern: function() {
var x,y;
var count;
var hue;
this.BlankArray();
for(count = 0; count < this.points; count++) {
x = Math.floor(Math.random()*this.width);
y = Math.floor(Math.random()*this.height);
hue = Math.floor(Math.random()* 360);
this.data[x][y].age = 0;
this.data[x][y].hue = hue;
this.data[x][y].saturation = 100;
this.data[x][y].light = 50;
}
return;
},
Move0: function(x,y) {
this.data[x+1][y].age = 0;
this.data[x+1][y].hue = this.data[x][y].hue;
this.data[x+1][y].saturation = 100;
this.data[x+1][y].light = 50;
return;
},
Move1: function(x,y) {
if (this.data[x][y].age >= 0) {
this.data[x][y].light += this.lightChange;
if (this.data[x][y].light <= 0 || this.data[x][y].light >= 100) {
this.data[x][y].age = -1;
} else {
this.data[x][y].age++;
}
}
return;
},
Move: function() {
var x,y, nextX;
for(y=0;y < this.height;y++) {
this.Move1(this.width-1, y);
}
for(x=this.width-2;x>=0;x--) {
for(y=0;y < this.height;y++) {
if (this.data[x][y].age == 0) {
this.Move0(x,y);
}
this.Move1(x,y);
}
}
this.Redisplay();
return;
},
Background Color:
<select id="BGColor" onchange="canvas.SetClearColor(this.value); canvas.Redisplay()">
<option value="white">white</option>
<option value="black">black</option>
</select>