xxxxxxxxxx
77
function createRose() {
var Rose = createFlower("rose", 30);
return Rose;
}
function createDaisy() {
var Daisy = createFlower("daisy", 20);
return Daisy;
}
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,
bumps: function(flo) {
if (flo.type == "rose" && this.type != "violet") {
if (this.s/2 + flo.s/2 >= this.pos.dist(flow.pos)) {
return true;
}
} else {
return false;
}
},
update: function() {
if (this.kind == "rose") {
this.petal = color(145, 0, 0);
this.center = color(255,0,0);
} else 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();
},
moves: function() {
if (this.type == "rose") {
if (this.pos.y > 20) {
this.pos.y--;
}
} else {
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;
}