xxxxxxxxxx
// DILATION BY WAJEEH KHAN - AUGUST 19th, 2024
Eye playerEye;
// BUTTON SIZE
float a = 325;
float b = 0;
float c = 100;
float d = 40;
// EYE VALUES
float dilationFactor = 1;
float maxpSize = 200/2.2;
float minpSize = 25; /// 200 / 8
// BACKGROUND VALUES
int bgcolor = 255;
int antibg;
void setup() {
size(750, 750);
frameRate(30);
playerEye = new Eye(width/2, height/2, 200); // Player eye
}
void draw() {
background(bgcolor);
playerEye.update(mouseX, mouseY);
playerEye.display();
if (bgcolor == 255){
antibg = 0;
} else {
antibg = 255;
}
// Hover over light source
if(mouseX > a && mouseX < a+c && mouseY > b && mouseY < b+d){
cursor(HAND);
} else {
cursor(ARROW);
}
// LIGHT BULB
fill(255,215,0);
noStroke();
arc(375, 0, 80, 60, 0, PI, OPEN);
noFill();
rect(a,b,c,d);
fill(antibg);
}
class Eye {
int x, y;
float size;
float angle = 0.0;
Eye(int tx, int ty, int ts) {
x = tx;
y = ty;
size = ts;
}
// Eye angle
void update(int mx, int my) {
angle = atan2(my-y, mx-x);
}
void display() {
stroke(0);
// BLACK => Dilate pupil
if(bgcolor == 0){
if(minpSize * dilationFactor == maxpSize){
dilationFactor = 8/2.2;
} else if(minpSize * dilationFactor < maxpSize){
dilationFactor += 0.23;
}
}
// WHITE Dilate pupil
if(bgcolor == 255){
if(minpSize * dilationFactor == minpSize){
dilationFactor = 1;
} else if(minpSize * dilationFactor > minpSize){
dilationFactor -= 0.01;
}
}
pushMatrix();
strokeWeight(16);
translate(x, y);
// Eye white
fill(255);
ellipse(0, 0, size, size);
rotate(angle);
fill(0); // Black pupil
// Pupil
ellipse((minpSize/2) * dilationFactor, 0, dilationFactor * minpSize, dilationFactor * minpSize);
popMatrix();
}
}
void mousePressed(){
if(mouseX > a && mouseX < a+c && mouseY > b && mouseY < b+d){
if(bgcolor == 255){
bgcolor = 0;
} else {
bgcolor = 255;
}
}
}