# Making my stick figure blink

**URL:** https://discourse.processing.org/t/making-my-stick-figure-blink/16934
**Category:** Coding Questions
**Created:** [January 7, 2020, 3:48pm UTC](https://discourse.processing.org/t/making-my-stick-figure-blink/16934 "2020-01-07T15:48:17Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Kvigna](https://avatars.discourse-cdn.com/v4/letter/k/b2d939/32.png) [@Kvigna](https://discourse.processing.org/u/Kvigna)
#### Post date: [January 7, 2020, 3:48pm UTC](https://discourse.processing.org/t/making-my-stick-figure-blink/16934/1 "2020-01-07T15:48:17Z")

</div>

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);  
}

---

<div class="post-metadata">

### Author: ![Tiemen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tiemen/32/5477_2.png) [@Tiemen](https://discourse.processing.org/u/Tiemen)
#### Post date: [January 7, 2020, 4:30pm UTC](https://discourse.processing.org/t/making-my-stick-figure-blink/16934/2 "2020-01-07T16:30:43Z")

</div>

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:

```auto
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](https://processing.org/reference/else.html) 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`.

---

<div class="post-metadata">

### Author: ![Kvigna](https://avatars.discourse-cdn.com/v4/letter/k/b2d939/32.png) [@Kvigna](https://discourse.processing.org/u/Kvigna)
#### Post date: [January 8, 2020, 1:17am UTC](https://discourse.processing.org/t/making-my-stick-figure-blink/16934/4 "2020-01-08T01:17:48Z")

</div>

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

```auto
     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);
}
```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 8, 2020, 4:12am UTC](https://discourse.processing.org/t/making-my-stick-figure-blink/16934/5 "2020-01-08T04:12:22Z")

</div>

add a  
[https://processing.org/reference/mousePressed\_.html](https://processing.org/reference/mousePressed_.html)

function and  
toggle a boolean variable blink

and then use in draw  
what @Tiemen suggested

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

void mousePressed() {
  blink = ! blink;
}

```

a much shorter version would be

```auto
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

```auto
</> 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!
