xxxxxxxxxx
54
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
// Evolution EcoSystem
// A collection of food in the world
function preload(){
getAPIMeaningData(baseWord);
}
class Food {
constructor(num) {
// Start with some food
this.food = [];
this.text=rhymeList[floor(random(rhymeList.length))].word
for (let i = 0; i < num; i++) {
this.food.push(createVector(random(width), random(height)));
}
}
// Add some food at a location
add(l) {
this.food.push(l.copy());
let n=0;
this.text='food';
}
// Display the food
run() {
for (let i = 0; i < this.food.length; i++) {
let f = this.food[i];
stroke(0);
fill(127);
text(this.text, f.x, f.y);
}
// There's a small chance food will appear randomly
if (random(1) < 0.001) {
this.food.push(createVector(random(width), random(height)));
}
}
// Return the list of food
getFoodText(){
return this.text;
}
getFood() {
return this.food;
}
}