How can you add a triangle to the Buttons example ? heres the LINK for the example -
http://processing.org/learning/topics/button.html
I tried doing it using the method :
int rectX, rectY; // Position of square button
int circleX, circleY; // Position of circle button
int triangX, triangY; // Position of triangle button
int rectSize = 50; // Diameter of rect
int circleSize = 53; // Diameter of circle
int triangleSize = 53; // Diameter of triangle
color rectColor, circleColor,triangColour, baseColor;
color rectHighlight, circleHighlight, colour triangHighLight;
color currentColor;
boolean rectOver = false;
boolean circleOver = false;
boolean triangOver = false;
int circleX, circleY; // Position of circle button
int triangX, triangY; // Position of triangle button
int rectSize = 50; // Diameter of rect
int circleSize = 53; // Diameter of circle
int triangleSize = 53; // Diameter of triangle
color rectColor, circleColor,triangColour, baseColor;
color rectHighlight, circleHighlight, colour triangHighLight;
color currentColor;
boolean rectOver = false;
boolean circleOver = false;
boolean triangOver = false;
void setup()
{
size(200, 200 , 200);
smooth();
rectColor = color(0);
rectHighlight = color(51);
circleColor = color(255);
circleHighlight = color(204);
triangColour = colour(47);
trinagHighlight = colour(102);
baseColor = color(102);
currentColor = baseColor;
circleX = width/2+circleSize/2+10;
circleY = height/2;
rectX = width/2-rectSize-10;
rectY = height/2-rectSize/2;
triangX = width/2-triangSize-10;
triangY = height/2-triangSize/2;
ellipseMode(CENTER);
}
{
size(200, 200 , 200);
smooth();
rectColor = color(0);
rectHighlight = color(51);
circleColor = color(255);
circleHighlight = color(204);
triangColour = colour(47);
trinagHighlight = colour(102);
baseColor = color(102);
currentColor = baseColor;
circleX = width/2+circleSize/2+10;
circleY = height/2;
rectX = width/2-rectSize-10;
rectY = height/2-rectSize/2;
triangX = width/2-triangSize-10;
triangY = height/2-triangSize/2;
ellipseMode(CENTER);
}
void draw()
{
update(mouseX, mouseY);
background(currentColor);
if(rectOver) {
fill(rectHighlight);
} else {
fill(rectColor);
}
stroke(255);
rect(rectX, rectY, rectSize, rectSize);
if(circleOver) {
fill(circleHighlight);
} else {
fill(circleColor);
}
stroke(0);
ellipse(circleX, circleY, circleSize, circleSize);
if(triangOver) {
fill(triangHighlight);
} else {
fill(rectColor);
}
stroke(102);
rect(triangX, triangY, triangSize, triangSize);
}
{
update(mouseX, mouseY);
background(currentColor);
if(rectOver) {
fill(rectHighlight);
} else {
fill(rectColor);
}
stroke(255);
rect(rectX, rectY, rectSize, rectSize);
if(circleOver) {
fill(circleHighlight);
} else {
fill(circleColor);
}
stroke(0);
ellipse(circleX, circleY, circleSize, circleSize);
if(triangOver) {
fill(triangHighlight);
} else {
fill(rectColor);
}
stroke(102);
rect(triangX, triangY, triangSize, triangSize);
}
void update(int x, int y)
{
if( overCircle(circleX, circleY, circleSize) ) {
circleOver = true;
rectOver = false;
triangOver = false;
} else if ( overRect(rectX, rectY, rectSize, rectSize) ) {
rectOver = true;
circleOver = false;
triangOver = false;
} else if (overTriang(triangX, triangY, triangSize, triangSize) ) {
triangOver = true;
rectOver = false;
circleOver = false;
} else {
circleOver = rectOver = triangOver = false;
}
}
{
if( overCircle(circleX, circleY, circleSize) ) {
circleOver = true;
rectOver = false;
triangOver = false;
} else if ( overRect(rectX, rectY, rectSize, rectSize) ) {
rectOver = true;
circleOver = false;
triangOver = false;
} else if (overTriang(triangX, triangY, triangSize, triangSize) ) {
triangOver = true;
rectOver = false;
circleOver = false;
} else {
circleOver = rectOver = triangOver = false;
}
}
void mousePressed()
{
if(circleOver) {
currentColor = circleColor;
}
if(rectOver) {
currentColor = rectColor;
}
if(triangOver) {
currentColour = triangColour;
}
}
{
if(circleOver) {
currentColor = circleColor;
}
if(rectOver) {
currentColor = rectColor;
}
if(triangOver) {
currentColour = triangColour;
}
}
boolean overRect(int x, int y, int width, int height)
{
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
{
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
boolean overCircle(int x, int y, int diameter)
{
float disX = x - mouseX;
float disY = y - mouseY;
if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
boolean overTriang(int x, int y, int width, int height)
{
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
{
float disX = x - mouseX;
float disY = y - mouseY;
if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
boolean overTriang(int x, int y, int width, int height)
{
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
1