xxxxxxxxxx
var enemy, enemy2;
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
enemy = new Enemy();
rectMode(CENTER);
fill(0);
textSize(16);
textAlign(CENTER);
}
function draw() {
background(0,50);
translate(width/2,height/2);
fill(255);
text("Key Press to random the shape",0,200);
enemy.display();
}
function keyPressed(){
enemy = new Enemy();
}
function Enemy() {
this.shape = parseInt(random(3));
this.size = 0;
this.display = function() {
push();
noFill();
stroke(255);
strokeWeight(0.5);
if (this.size < 10) {
this.shape = parseInt(random(3));
this.size++;
}
switch(this.shape) {
case 0:
ellipse(0,0,20 * this.size,20 * this.size);
break;
case 1:
rect(0,0,20 * this.size,10 * this.size);
break;
case 2:
rect(0,0,20 * this.size,20 * this.size);
break;
}
pop();
}
}