increase brightness with y pos
in
Programming Questions
•
1 year ago
hi, trying to increase the brightness of circle as you drag it upwards(going from black at bottom to white at top). I've put a conditional for this in void display method. Any help?
Button[] buttons = new Button[1];
boolean somethingSelected = false;
void setup() {
size(800, 300);
smooth();
for (int i = 0; i < buttons.length; i++) {
buttons[i]= new Button(width/2, 250, random(20, 80), color(0), 0.5);
}
}
void draw() {
background(85);
for (int i = 0; i < buttons.length; i++) {
buttons[i].display();
}
}
void mousePressed() {
somethingSelected = false;
for (int i = 0; i < buttons.length; i++) {
buttons[i].rollOver();
buttons[i].doubleclick();
buttons[i].originalSize();
}
}
void mouseDragged() {
for (int i = 0; i < buttons.length; i++) buttons[i].bDragged();
}
void mouseReleased() {
for (int i = 0; i < buttons.length; i++) buttons[i].bReleased();
}
class Button {
float x;
float y;
float rad;
color c;
float s;
boolean click = false;
boolean drag = true;
boolean dclick=false;
boolean originalSize=false;
Button(float _x, float _y, float _radius, color _c, float _s) {
x=_x;
y=_y;
rad=_radius;
c=_c;
s=_s;
}
void display() {
if (click) {
fill(c);
c+=y;
strokeWeight(3);
}
else {
fill(0);
strokeWeight(s);
}
ellipse (x, y, rad, rad);
rad= constrain(rad, rad, rad*2);
}
void rollOver() {
if (sqrt(sq(mouseX-x)+sq(mouseY-y)) <= rad/2 && somethingSelected == false) {
click = true;
drag = true;
}
}
void doubleclick() {
if (sqrt(sq(mouseX-x)+sq(mouseY-y)) <= rad/2 && somethingSelected == false&&mouseEvent.getClickCount()==2) {
rad=rad*2;
//rad= constrain(rad,rad,rad*2);
}
}
void originalSize() {
if (sqrt(sq(mouseX-x)+sq(mouseY-y)) <= rad/2 && somethingSelected == false&& key=='r'&& dclick==true )
{
println ("half");
rad=rad/2;
}
}
void bDragged() {
if (drag) {
x = mouseX;
y = mouseY;
}
}
void bReleased() {
click = false;
drag = false;
}
}
1