Help with my color?
in
Programming Questions
•
2 years ago
Hello guys, I've been thinking on how to properly set my 'generateRandomColor' function to cooperate and I'm getting nowhere. I'm aware it's getting results but they're not being used, perhaps it's a simple fix and I'm overlooking it, I don't know anymore, lol.
Basically what I'm trying to do is for the triangles and squares to have a random color.
Anyway here's my code:
I'm going insane studying for finals and I have this processing hwk, so any thing will be GREATLY appreciated!
Basically what I'm trying to do is for the triangles and squares to have a random color.
Anyway here's my code:
float a;
float b;
float theta;
float r;
boolean square = true;
void setup()
{
size(400, 400);
background(255);
smooth();
startNewDrawing();
generateRandomColor();
}
void draw()
{
float x;
float y;
//Convert formula
r = sin (a * theta) + cos (b * theta);
x = r * cos(theta);
y = r * sin(theta);
//Muliply to lengthen lines
x = x * 75;
y = y * 75;
//Things to draw
if (square)
{
pushMatrix();
translate(200 , 200);
rotate(theta);
triangle(x, y - 5, x - 5, y + 5, x + 5, y + 5);
theta = theta + PI/60.0;
popMatrix();
}
else
{
pushMatrix();
translate(200, 200);
rotate( theta);
rect(x, y, 10, 10);
theta = theta + PI/60.0;
popMatrix();
}
}
void mousePressed()
{
startNewDrawing();
}
void startNewDrawing()
{
background(255);
theta = 0;
a = int(random(0, 21))/4.0;
b = int(random(0, 16))/3.0;
}
//cant figure out how to make this part show up in the draw
color generateRandomColor()
{
//color result;
color result = color(random(0, 255), random(0, 255), random(0, 255),
random(192, 255));
return result;
}
void keyPressed()
{
if(key == 's' || key == 't')
{
square = !square;
startNewDrawing();
}
}
I'm going insane studying for finals and I have this processing hwk, so any thing will be GREATLY appreciated!
1