Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update #1

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 57 additions & 21 deletions Plant.pde
Original file line number Diff line number Diff line change
@@ -1,21 +1,57 @@
class Plant {
String name;
int time;
float sun, fertilizer, water;
float rangeS, rangeF, rangeW, growthFactor;
boolean dying;
color foilage;
Plant(String name) {
this.time = 0;
this.name = name;
}
float growth() {
int growths = 0;
growths += growthFactor * (rangeS - pow((sun - sqrt(rangeS)),2.0));
growths += growthFactor * (rangeF - pow((fertilizer - sqrt(rangeF)),2.0));
growths += growthFactor * (rangeW - pow((water - sqrt(rangeW)),2.0));
return growths;
}
void grow() {
}
}
class Plant {
String name;
int time;
float rangeS, rangeF, rangeW, growthFactor;
boolean dying;
int foliageR;
int foliageG;
int foliageB;
float maxHeight;
float stemLength;
float stemWidth;
Plant(String n, float mh, float gf, int fR, int fG, int fB) {
this.time = 0;
this.name = n;
this.maxHeight = mh;
this.dying = false;
this.growthFactor = gf;
this.stemLength = 0;
this.foliageR = fR;
this.foliageG = fG;
this.foliageB = fB;
this.stemWidth = 0;
}
float growth() {
int growths = 0;
growths += 9- growthFactor *(sq(0.65*fertilizer.getValueF()));
growths += 5 - growthFactor * (sq(.9 * water.getValueF()));
growths += 5 - growthFactor * 3 * sin((PI * 2 * sunlight.getValueF())/360);
if (growths<0) {
this.dying = true;
}
return growths/10;
}
void grow() {
textSize(40);
fill(255);
//text(this.name, 40, 120);
if (this.dying) {
if (foliageR < 79) foliageR +=1;
} else {
if (foliageR > 40) foliageR -=1;
}
if ( (this.stemLength + growth()) > 0 && this.stemLength + growth() < this.maxHeight) {
this.stemLength += growth();
} else if (this.stemLength + growth() > 0) {
} else {
this.stemLength = 0;
}
background(5, 141, 4);
pot();
this.stemWidth = this.stemLength/10;
rect(width/2 - this.stemWidth/2, height/2, width/2 + this.stemWidth/2, height/2 - this.stemLength);
if (!this.dying) {
circle(width/2, height/2 - this.stemLength, this.stemLength/5);
}
}
}
110 changes: 90 additions & 20 deletions Plant_Grower.pde
Original file line number Diff line number Diff line change
@@ -1,20 +1,90 @@
import g4p_controls.*;

ArrayList<Plant> plants = new ArrayList<Plant>();
Sunflower hi = new Sunflower("Hi");
int midX = 300;
int groundLevel = 500;
int whichPlant = 0;

void setup() {
size(600,600);
createGUI();
for(int i = 0; i < 5; i++) {
plants.add(new Sunflower("sunflower"+i));
}
}

void draw() {
background(0);
plants.get(whichPlant).grow();
}
import g4p_controls.*;
Plant[] plants = new Plant[12];
HashMap<String, JSONObject> plantTraits = new HashMap<String, JSONObject>();
Plant present;
PFont font;
Button[] bArr = new Button[12];
Button start;
boolean plantClick = false;
int plantIndex = -1;
boolean begin;
boolean plantView = false;


void setup() {
JSONObject sunflower= generateTraits("Sunflower", height/2, 3.0 , 4, 5, 6); // name, max height, growth factor, foliage RGB
plantTraits.put("Sunflower", sunflower);
JSONObject tomato = generateTraits("Tomato", 3.0, 3.5, 5, 194, 3);
plantTraits.put("Tomato", tomato);
begin = false;
font = createFont("Inter-Bold.ttf", 50);
textFont(font);
background(5, 141, 4);
fill(0);
menu();


size(800,600);
createGUI();
textSize(50);

}
void menu(){
text("Plant Grower", width/2 -150, height/4);

start = new Button(width/2-50, height/3 -25, width/2 +50, height/3 +25, true);
start.pack(106, 76, 3);
start.label("START");
}
void pots(){
int padding = 100;
for(int i =0; i < 12; i++){
Button b = new Button(float((i%6)*125 + padding), (i/6)*125 + 300.0, 100.0);
b.pack(106, 76, 3);
bArr[i] = b;

}
fill(0);
text("Pick Your Pot", width/2 -150, height/4);
}
int overButtons(Button[] buttonArray){
for(int i = 0; i<buttonArray.length; i++){
if(buttonArray[i].overButton()){
return i;
}
}
return -1;
} void pot(){
fill(106, 76, 3);

quad(width/2 - 100, height/2 +25, width/2 +100, height/2 +25, width/2 +50, height/2 + 175, width/2 -50, height/2 + 175);
rect(width/2 - 110, height/2, width/2 +110, height/2 + 35);
fill(0);
rect(0.0, height/2 + 175, 800.0, height);

}
void mousePressed(){
if(start.overButton() && start.start){
background(5, 141, 4);
pots();
begin = true;
}
if(begin){
if(overButtons(bArr) !=-1){
plantIndex = overButtons(bArr);
background(5, 141, 4);
fill(106, 76, 3);
plantView = true;
pot();

}
}

}


void draw() {
if(plantView && plantClick){
present.grow();
}
}
42 changes: 0 additions & 42 deletions Sunflower.pde

This file was deleted.

33 changes: 0 additions & 33 deletions Sunflower6465070237851525127.autosave

This file was deleted.

76 changes: 38 additions & 38 deletions Tomato.pde
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
class Tomato extends Plant {
ArrayList<Leaf> leaves;
int stemLength;
int stemThickness;
Tomato(String name) {
super(name);
stemLength = 0;
this.name = name;
this.dying = false;
this.leaves = new ArrayList<Leaf>();
}

void grow () {
dying = this.time > 200;
if(dying) {
time = 800-time;
this.foilage = color(124,252,0);
} else {
this.foilage = color(255, 99, 71);
}
stemLength = time;
stemThickness = 2+(time/50);
fill(foilage);
rect(midX-stemThickness,groundLevel,stemThickness*2,-stemLength);
if(time > 300) {
fill(255, 0, 0);
circle(midX,groundLevel-stemLength,time/2-100);
} else if(time > 200) {
fill(foilage);
circle(midX,groundLevel-stemLength,time/2-100);
}
if(dying) {
time = 800-time;
}
time++;
}

}
/*class Tomato extends Plant {
ArrayList<Leaf> leaves;
int stemLength;
int stemThickness;
Tomato(String name) {
super(name);
stemLength = 0;
this.name = name;
this.dying = false;
this.leaves = new ArrayList<Leaf>();
}
void grow () {
dying = this.time > 200;
if(dying) {
time = 800-time;
this.foilage = color(124,252,0);
} else {
this.foilage = color(255, 99, 71);
}
stemLength = time;
stemThickness = 2+(time/50);
fill(foilage);
rect(midX-stemThickness,groundLevel,stemThickness*2,-stemLength);
if(time > 300) {
fill(255, 0, 0);
circle(midX,groundLevel-stemLength,time/2-100);
} else if(time > 200) {
fill(foilage);
circle(midX,groundLevel-stemLength,time/2-100);
}
if(dying) {
time = 800-time;
}
time++;
}
}*/
12 changes: 12 additions & 0 deletions Traits.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
JSONObject generateTraits(String n, float mh, float gf, int fR, int fG, int fB){
JSONObject plantTrait = new JSONObject();

plantTrait.setString("Name", n);
plantTrait.setFloat("Max Height", mh);
plantTrait.setFloat("Growth Factor", gf);
plantTrait.setInt("Foliage Red", fR);
plantTrait.setInt("Foliage Green", fG);
plantTrait.setInt("Foliage Blue", fB);

return plantTrait;
}
Loading