Assignment 1: Drawing Machine

I wanted to do something with flowers for this project and I love how trees look with flowers, so I made a cherry blossom type of tree. I wanted to simulate a kind of shimmering motion so I utilized the random function and changed the colors of the petals based on the mouse position.

My code:

// Dimensions of the screen size
int x = 1000;
int y = 900;
PImage tree;
ArrayList<Petal> petals = new ArrayList<Petal>();
int[] shades = { #EAD5D9, // dimmest pink
#EDD2D7,
#F0CFD5,
#F4CBD2,
#F9C6CF, // pink
#F54363
};

/* Color references
* #FFCBEC Pink
* #A78C7A Brown
* #303030 Tree Black
* #CBCBCB Light Gray
*/

void setup() {
size(1000, 900);

// Load and display tree image
tree = loadImage(“tree.png”);

// create Petal objects and set to a random color from the arrayList
for (int i = 0; i < 700; i++) {
int shadeColor = int(random(6));
petals.add(new Petal(random(80, 900), random(51, 520), shades[shadeColor]));
}
}

void draw() {
// For shape placement
//println(mouseX + “, ” + mouseY);
background(#CBCBCB);
image(tree, 0, 0); //display tree image

// loop through the array list and display the petal
for (int i = 0; i < petals.size()-1; i++) {
Petal petal = petals.get(i);
petal.display();

if (mouseX >= (int)petal.getX() && mouseY >= (int)petal.getY()) {
int shadeColor = int(random(6));
petal.setShade(shades[shadeColor]);
petal.display();

}
}

}

 

//Petal Class

class Petal {
float x; // x coordinate of petal
float y; // y coordinate of petal
int shade; // shade of pink

Petal(float xCoo, float yCoo, int theShade) {
x = xCoo;
y = yCoo;
shade = theShade;
}

void setShade(int theShade) {
shade = theShade;
}

float getX() {
return x;
}

float getY() {
return y;
}

void display() {
noStroke();
fill(shade);
ellipse(x, y, 30, 30);
}

void flutter() {
if (random(6) % 2 == 0) {
x += 2;
display();
} else {
x -= 2;
display();

}
}
}