Making my stick figure blink

Hi! I’m trying to figure out how I would make the eyes of my stick figure blink. Please help me figure it out.
My code is:

//Drawing a character

void setup(){
size(400,400);
background(200,255,100);
}

void draw(){
background(100,100,200);
smooth();
strokeWeight(3);
rect(85,100,30,65); //body x y w h

ellipse(100,100,50,50); //head
ellipse(90,95,20,20); //left eye
ellipse(110,95,20,20); //right eye
fill(#3662E0);
ellipse(90,95,10,10); //left inside
ellipse(110,95,10,10); //right inside
fill(255);

ellipse(100,115,10,5); //mouth
line(85,120,70,160); //left arm
line(115,120,130,160); //right arm
line(95,168,84,200); //left leg
line(110,168,125,200);
ellipse(71,163,15,15);

text((mouseX + “,” + mouseY), 13,13);
}

Hi Kvigna, welcome to the forum!

First, could you please edit your post and format your code using the < /> Preformatted text button? This way spaces, tabs and special characters stay intact when you copy-paste from Processing. The outcome should look something like this:

void setup() {
  size(400, 400);
}

void draw() {
  // rest of your code
}

In your current sketch you draw the eyes as ellipses, and at certain moments you want your stick figure to blink. For this situation if/else comes in handy. If something is true the eyes should blink, otherwise (else) draw the eyes as ellipses.
There are different ways to let him blink, what do you prefer? Randomly? When you press the mouse button?

You can also move the line smooth(); to setup, it’s not needed to call it each time in void draw.

Hi thanks for responding I would prefer if my stick figure could blink when the mouse is pressed. I’m not really sure how I would go about doing this?
My code done in the correct format is:
//Drawing a character

void setup(){
size(400,400);
background(200,255,100);
}

void draw(){
background(100,100,200);
smooth();
strokeWeight(3);
rect(85,100,30,65); //body x y w h

     ellipse(100,100,50,50); //head
     ellipse(90,95,20,20); //left eye
     ellipse(110,95,20,20); //right eye
     fill(#3662E0);
     ellipse(90,95,10,10); //left inside
     ellipse(110,95,10,10); //right inside
     fill(255);

     ellipse(100,115,10,5); //mouth
     line(85,120,70,160); //left arm
     line(115,120,130,160); //right arm
     line(95,168,84,200); //left leg
     line(110,168,125,200);
     ellipse(71,163,15,15);

     text((mouseX + “,” + mouseY), 13,13);
}

add a
https://processing.org/reference/mousePressed_.html

function and
toggle a boolean variable blink

and then use in draw
what @Tiemen suggested

boolean blink;
//... and in 
void draw() {
//...
if (  blink ) { }
else { } 
//...
}

void mousePressed() {
  blink = ! blink;
}

a much shorter version would be

void draw() {
//...
if (  mousePressed  ) { }
else { } 
//...
}


but that reacts in a different way as the above code,
only acts as long mouse button is pressed.

please test both.


please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


it is required that you format your code
means also to REPAIR that in your first post!

2 Likes