xxxxxxxxxx
72
function createViolet() {
var Violet = createFlower("violet", 10);
return Violet;
}
function createFlower( k,s ) {
var Flower = {
kind: k,
petal: color(255),
center: color(255,255,0),
pos: createVector(random(100, 300), random(100,300)),
size: s,
place: 15,
age: 0,
hasCollision: function(other) {
if (other.kind == "violet") {
if (this.size/2 + other.size/2 >= this.pos.dist(other.pos) ){
return "daisyeatsviolet";
} else {
return false;
}
} else {
return false;
}
return true;
},
update: function() {
if (this.kind == "violet") {
this.petal = color(222, 212, 255);
this.place = 5;
} else { // default is daisy
this.petal = color(255);
this.center = color(255,255,0);
}
this.lookslike();
this.moves();
this.age++;
if (this.age > 200) {
this.pos.y = 0;
}
},
moves: function() {
if (this.pos.y < 380) {
this.pos.y++;
}
},
lookslike: function() {
noStroke();
fill(this.petal);
ellipse(this.pos.x - this.place, this.pos.y, this.size);
ellipse(this.pos.x + this.place, this.pos.y, this.size);
ellipse(this.pos.x, this.pos.y - this.place, this.size);
ellipse(this.pos.x, this.pos.y + this.place, this.size);
ellipse(this.pos.x + this.place*.75, this.pos.y + this.place*.75, this.size);
ellipse(this.pos.x - this.place*.75, this.pos.y + this.place*.75, this.size);
ellipse(this.pos.x - this.place*.75, this.pos.y - this.place*.75, this.size);
ellipse(this.pos.x + this.place*.75, this.pos.y - this.place*.75, this.size);
fill(this.center);
ellipse(this.pos.x, this.pos.y, this.size);
}
}
return Flower;
}