Assignment 1- Drawing Machine

/*
* A project in processing by Laurel Doak:
* Art 150 project 1, UIC
*
* Interactive flower field
*/

//Global saved data
color grassFill = #1C8300;
color grassStroke = #57B43E;
ArrayList <Flower>flower_field = new ArrayList();

void setup() {
size(500, 500);
background(255);
}
void keyPressed()
{
if (key == ‘s’ )
{
saveFrame(“drawing-####.png”);
}
//A way to wipe the field if you want to start over
if (key == ‘c’)
{
background(255);
flower_field.clear();
}
//Draw a “flower” (maybe it’s a dandelion…). Final version will be more complicated.
if (key == ‘n’)
{
//Random values for location of one end of the line and color of the circle
float xCoord = random(50, 450);
float yCoord = random(50, 450);
stroke(0);
strokeWeight(4);
//Depending on which Left/Right half of the canvas your cursor is currently on, decides
//where the “flower” is going to come up from and draw. Random lines technique
//adapted from the “random lines” example
if (mouseX < 250) {
line(xCoord, yCoord, 500, 500);
} else {
line(xCoord, yCoord, 0, 500);
}
Flower newFlower = new Flower(xCoord, yCoord);
flower_field.add(newFlower);
}
}
//An attempt at making a reaction to a mouseclick on specific objects
void mousePressed()
{
for (int i = 0; i < flower_field.size(); i++)
{
if (flower_field.get(i).is_On(mouseX, mouseY))
{
//Redraw method should contain reaction
flower_field.get(i).redraw();
flower_field.remove(i);
}
}
}
void mouseDragged()
{
//This chunk draws triangles, creating an effect I thought looked something like grass
fill(grassFill, 150);
strokeWeight(1);
stroke(grassStroke, 150);
if (random(1) == 1) {
triangle(mouseX, mouseY, mouseX-5, 500, mouseX+15, 500);
} else {
triangle(mouseX, mouseY, mouseX-15, 500, mouseX+5, 500);
}
}

void draw() {}

 

class Flower {
float xCoord, yCoord;
float colorValue;
float color2;
//This was originally going to determine type of click effect,
//turned out to be useful anyway
boolean is_fire;
/*
* Constructor, draws flower head immediately. Random values for colors.
*/
Flower(float x, float y) {
xCoord = x;
yCoord = y;
colorValue = random(170);
color2 = random(100);
color flowerColor;
if ((xCoord<250 && yCoord > 250)||(xCoord>250 && yCoord < 250)) {
flowerColor = color(255, 255-color2, colorValue);
is_fire = true;
} else {
flowerColor = color(255-colorValue, 100-color2, 255-color2);
is_fire = false;
}
drawPattern(flowerColor);

}
//Since the object contains the location, a way to check if coordinate arguments
//fall within the circle. I absolutely remembered basic geometry to do this
//and didn’t have to look it up at all. Totally.
boolean is_On(int x, int y)
{
float offsetX = xCoord-(float)x;
float offsetY = yCoord-(float)y;
if (sqrt(sq(offsetX) + sq(offsetY)) < 20) {
return true;
} else {
return false;
}
}
void redraw()
{
//The obnoxious-looking parentheses mess in each fill makes the color a paler
//version of the original color assigned to that flower
color flowerColor;
if (is_fire)
{
flowerColor = color(255, 255-(color2/2), 255-((255-colorValue)/2));
} else {
flowerColor = color(255-(colorValue/2), 100+color2, 255-(color2/2));
}
drawPattern(flowerColor);
}
void drawPattern(color myColor)
{
strokeWeight(3);
stroke(myColor);
translate(xCoord,yCoord);
for (int i = 0; i<360;i = i+15)
{
rotate(radians(i));
line(0,0,20,0);
}
resetMatrix();
}
}