We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys, new to the forums and could use some help please. I have a project and I am having a lot of trouble finding a way to figure it out and it is due next month. (http://people.ucalgary.ca/~jparker/art315/assignments/assignment2.html)
That is the project. So far all I have really been able to do is display the buttons for square and circle, and I even have the shapes for the colors. Only thing is I can't figure out how to make the colors work when I click the buttons and for some reason I can't get the images to display right.
color bgcolor = color (200, 200, 200);
int bx=10, by=20, bw=60, bh=30;
//int bx2=175, by2=20, bw2=60, bh2=30;
void setup()
{
size (250, 300);
}
void draw ()
{
//background (100);
fill(bgcolor);
//rect(50,100,100,100);
fill(200, 0, 0);
rect(80, 20, 20, 20);
fill(0, 200, 0);
rect(110, 20, 20, 20);
fill(0, 0, 200);
rect(140, 20, 20, 20);
drawButton();
drawButton2();
}
void drawButton()
{
if (buttonArmed()) fill (20, 200, 40);
else fill (200, 60, 80);
rect (bx, by, bw, bh);
fill (0);
text ("Square", bx+13, by+19);
}
boolean buttonArmed ()
{
if ( (mouseX>=bx) && (mouseX<bx+bw) &&
(mouseY>=by) && (mouseY<by+bh) ) return true;
return false;
}
void drawButton2()
{
if (buttonArmed2()) fill (20, 200, 40);
else fill (200, 60, 80);
rect(175, 20, 60, 30);
fill(10);
text ("Circle", 175+13, 20+19);
}
boolean buttonArmed2 ()
{
if ( (mouseX>=175) && (mouseX<175+60) &&
(mouseY>=20) && (mouseY<20+80) ) return true;
return false;
}
void mousePressed ()
{
if (buttonArmed())
background (100);
bgcolor = color(random(128, 255), random(128, 255), random(128, 255));
rect(50, 100, 100, 100);
if (buttonArmed2())
background (100);
bgcolor = color(random(128, 255), random(128, 255), random(128, 255));
ellipse(50, 100, 100, 100);
}
This is what I have so far. Please help me.
Answers
Please format your code. Edit your post (gear on top right side of any of your posts), select your code and hit ctrl+o. Leave an empty line above and below your block of code. Details here: https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Kf
crap how do I unanswer this lol
You draw stuff in the function mousePressed directly
This is not the way to do it
Instead in mousePressed set a variable or a flag like drawCircleShape to true.
See boolean in the reference
In draw check the Boolean variable with if:
if(drawC.......)
And draw stuff there
please don't post duplicates
Your vocabulary of processing commands is still small
So your approach is not very good
You could have a list of button positions x and a second list for y
Read the tutorial on arrays in the array section please
Look at Arrays and Booleans, I did an none of it made sense to me...
??
boolean:
before setup () :
drawCirckeShape=false;
In mousePressed instead of rect circle set this variable to true. It’s a marker or flag.
Now in draw use
if ( drawCirckeShape )
ellipse(......); // what you have in mousePressed now
Arrays :
Forget it
Not important