//Fruit dropped from tree class Seed{ int num; //Iteration of parent tree Particle me; //Object handling physical presence boolean active = false; //On screen? boolean treeSucking = false; //Parent tree being destroyed? boolean mouseLock = false; //Being dragged by mouse? boolean fading = false; //Fade seed? int hopper = 30; //Timer for seed disappearing Seed(int num){ this.num = num; me = physics.makeParticle(1.0, 0, 0, 0); } //Put on screen void activate(float x, float y){ me.moveTo(x, y, 0); me.setVelocity(0,0,0); active = true; } void draw(){ if(active){ update(); strokeWeight(1); fill(200, 200, 0); stroke(100,100,0); pushMatrix(); translate(me.position().x(), me.position().y()); rotate(rotationTable[constrain((int)me.position().x(), 0, width-1)]); ellipse(0, 0, 30, 30); fill(colorTable[num]); stroke(100,100,0); ellipse(0, 0, 20, 10); popMatrix(); } if(hopper > 0 && hopper < 30){ if(!fading){ strokeWeight(1); fill(200, 200, 0); stroke(100,100,0); pushMatrix(); translate(me.position().x(), me.position().y()); ellipse(0, 0, hopper, hopper); rotate(rotationTable[constrain((int)me.position().x(), 0, width-1)]); fill(colorTable[num]); ellipse(0, 0, ((float)hopper / 3) * 2, (float)hopper / 3); popMatrix(); } else{ strokeWeight(1); fill(200, 200, 0, (255 / 30) * hopper); stroke(100, 100, 0, (255 / 30) * hopper); pushMatrix(); translate(me.position().x(), me.position().y()); rotate(rotationTable[constrain((int)me.position().x(), 0, width-1)]); ellipse(0, 0, 30, 30); fill(220, 220, 0, (255 / 30) * hopper); stroke(100, 100, 0, (255 / 30) * hopper); ellipse(0, 0, 20, 10); popMatrix(); } hopper -= 2; if(hopper == 0 && !treeSucking){ active = false; garden.uploadChromosome(num); } } } //Manage physical presence against WhiteMountain object void update(){ if(mouseMode){ if(mousePressed && dist(mouseX, mouseY, me.position().x(), me.position().y()) < 30){ mouseLock = true; } else if (!mousePressed){ mouseLock = false; } if(mouseLock){ me.makeFixed(); me.moveTo(mouseX, mouseY, 0); } else { me.makeFree(); } } for(int i = 0; i < garden.hopper.length; i++){ if(dist(me.position().x(), me.position().y(), garden.hopper[i].x, garden.hopper[i].y) < 10){ hopper -= 2; active = false; me.makeFixed(); sound[hopperSound].stop(); sound[hopperSound].play(); } } int column = constrain((int)me.position().x() / screenColumnWidth, 0, graph.columns - 1); if(me.position().y() > graph.blanket[column].position().y() - 10){ me.moveTo(me.position().x(), graph.blanket[column].position().y() - 10, 0); me.setVelocity(me.velocity().x(), -me.velocity().y() / 2, 0); } if(me.position().x() < 0){ me.moveTo(0, me.position().y(), 0); me.setVelocity(-me.velocity().x() * 1.5, me.velocity().y(), 0); } if(me.position().x() > width){ me.moveTo(width, me.position().y(), 0); me.setVelocity(-me.velocity().x() * 1.5, me.velocity().y(), 0); } int rightColumn = constrain(column + 1, 0, graph.columns - 1); int leftColumn = constrain(column - 1, 0, graph.columns - 1); if(graph.blanket[rightColumn].position().y() < graph.blanket[column].position().y()){ float yDelta = abs(graph.blanket[rightColumn].position().y() - graph.blanket[column].position().y()); float xDelta = columnWidth; float gradient = yDelta / xDelta; me.addVelocity(constrain(-gradient,-1.5,1.5),0,0); } if(graph.blanket[leftColumn].position().y() < graph.blanket[column].position().y()){ float yDelta = abs(graph.blanket[leftColumn].position().y() - graph.blanket[column].position().y()); float xDelta = columnWidth; float gradient = yDelta / xDelta; me.addVelocity(constrain(gradient,-1.5,1.5),0,0); } } } //colours of seeds void initColors(){ colorTable = new color[treeNum]; colorTable[0] = color(255, 0, 0); colorTable[1] = color(0, 0, 255); colorTable[2] = color(255, 0, 255); //colorTable[3] = color(0, 255, 255); //colorTable[4] = color(255, 150, 0); }