I’m just getting started with Processing (3.5.3), and so far it’s been pretty fun. However, I’ve hit a snag, and even after researching for a couple hours I still can’t figure it out. I try to create two instances of circle with different parameters, but the last circle is the only one shows up.
int circleX, circleY; // Position of circle button
int circleSize = 50; // Diameter of circle
color circleColor, baseColor, circleHighlight, currentColor;
boolean circleOver = false;
void settings() {
size(500, 500);
}
void setup() {
}
void draw() {
ButtonObjectClass buttonObject = new ButtonObjectClass();
buttonObject.circleButton(255,255,0,-100,-10);
ButtonObjectClass buttonObject2 = new ButtonObjectClass();
buttonObject2.circleButton(255,0,0,100,10);
}
//Setting up the buttton class
class ButtonObjectClass{
void circleButton(int r, int g, int b, int xPos, int yPos)
{
circleColor = color(r,g,b);
circleHighlight = color(r/2,g/2,b/2);
baseColor = color(102);
circleX = width/2+circleSize/2+xPos;
circleY = height/2+yPos;
ellipseMode(CENTER);
update();
background(currentColor);
if (circleOver) {
fill(circleHighlight);
} else {
fill(circleColor);
}
stroke(0);
ellipse(circleX, circleY, circleSize, circleSize);
}
}
//Checks if mouse is hovering over button
void update() {
if ( overCircle(circleX, circleY, circleSize) ) {
circleOver = true;
}
else {
circleOver = false;
}
}
//Checks if mouse is pressed and prints "Button Pressed"
void mousePressed() {
if (circleOver) {
currentColor = circleColor;
println("Button Pressed");
}
}
//Determines actual size and location of button to determine if the mouse is touching it
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;
}
}
Can someone explain to me what I’m doing wrong and how to fix it?