New random event
Paint event: paints a random circle a random color
This commit is contained in:
parent
0856d7c04b
commit
b6dc65da7d
|
|
@ -0,0 +1,17 @@
|
|||
randomEvents.paint = function() {
|
||||
// set the color of a random circle to a random color
|
||||
var x = Math.floor(Math.random()*(width-1))+1;
|
||||
var y = Math.floor(Math.random()*(height-1))+1;
|
||||
var randomR = Math.floor(Math.random() * 256);
|
||||
var randomG = Math.floor(Math.random() * 256);
|
||||
var randomB = Math.floor(Math.random() * 256);
|
||||
var radius = Math.floor(Math.random()*4)+3;
|
||||
var rColor = "rgb(" + randomR + "," + randomG + "," + randomB + ")";
|
||||
var coords = circleCoords(x,y,radius);
|
||||
for (var i = 0; i < coords.length; i++) {
|
||||
var coord = coords[i];
|
||||
if (!outOfBounds(coord.x,coord.y) && !isEmpty(coord.x,coord.y)) {
|
||||
pixelMap[coord.x][coord.y].color = rColor;
|
||||
};
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue