xxxxxxxxxx
48
function createCircle() {
return createShape(random(10,30), "circle");
}
function createSquare() {
return createShape(random(10,30), "square");
}
function createShape(s, t) {
var shape = {
weight: s,
type: t,
position: createVector(random(width), random(height)),
velocity: createVector(random(5), random(5)),
red = random(0,255);
green: random(0,255),
move: function() {
this.position.add(this.velocity);
if ( position.x > width || position.x < 0) {
this.velocity.x = this.velocity.x * -1;
}
if ((position.y > height) || (position.y < 0)) {
this.velocity.y = this.velocity.y * -1;
}
},
display: function() {
if (this.type == "circle") {
fill(this.red, 200, 255);
ellipse(this.position.x, this.position.y, this.size, this.size);
} else {
fill(200, this.green, 0);
rect(position.x, position.y, this.size, this.size);
}
},
hascollision: function(obj) {
if (obj.size / 2 + this.size / 2 > this.position.dist(obj.position)) {
return true;
}
}
}
return shape;
}