Hello fellow programmers,
I need some help with my code. I’m trying to create eyes in processing that can blink. I want to be able to control each individual eyelid (left eye upper and lower lid and right eye upper and lower lid) of the eyes I’m creating. In order to achieve this, I started with just one eyelid (right eye upper eyelid). Unfortunately I didn’t succeed so far, because if I press the key (“b” in this case) it keeps on blinking.
How I want it to work:
If I press for example the key “b” I want the upper right eyelid to only blink ones, if I then push “b” again I want it to blink again. I tried using a while loop to track when the eyelid is back at the top again, but this doesn’t work.
I don’t know which thinking mistake I’m making, but hopefully there is someone who can help me!
int centerPointEye = 250;
int eyeDiameter = 150;
int radiusEye = eyeDiameter /2;
int rightEyeLidTop = centerPointEye - radiusEye; // highest possible point of eye lid right eye
int blinkSpeed = 3;
int posRightEyeLid = 1; //position of right eye lid
void setup() {
background(#ADE3A5);
size(500, 500);
noStroke();
}
void draw() {
background(#ADE3A5);
//eyes shapes
fill(255);
ellipse(150, centerPointEye, eyeDiameter, eyeDiameter);
ellipse(350, centerPointEye, eyeDiameter, eyeDiameter);
//pupils
fill(50);
ellipse(150, 250, 30, 30);
ellipse(350, 250, 30, 30);
if ((key == 'b') || (key == 'B')) {
blinkRightEyeLid();
}
}
void blinkRightEyeLid() {
//while(posWink !=0){
posRightEyeLid = posRightEyeLid + blinkSpeed;
fill(50); //will get the same color as background: #ADE3A5
rect(0, rightEyeLidTop, 250, posRightEyeLid);
if(posRightEyeLid > radiusEye){
blinkSpeed = -blinkSpeed;
}
if(posRightEyeLid < 0){
blinkSpeed = 1;
;
}
if(posRightEyeLid == 0){
}
//}
}
Thanks in advance!!