# Blinking images are too fast

**URL:** <https://discourse.processing.org/t/blinking-images-are-too-fast/21632>\
**Category:** Coding Questions\
**Created:** [June 6, 2020, 8:47pm UTC](https://discourse.processing.org/t/blinking-images-are-too-fast/21632 "2020-06-06T20:47:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SaltyBoy](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SaltyBoy](https://discourse.processing.org/u/SaltyBoy)\
**Post date:** [June 6, 2020, 8:47pm UTC](https://discourse.processing.org/t/blinking-images-are-too-fast/21632/1 "2020-06-06T20:47:00Z")

</div>

I want to blink some images in my Simon game, but they are blinking very short. You can hardly see that a light (image) is turned on.

```auto
boolean isPlayerReady = false;
ArrayList<Integer> gameList;
ArrayList<Integer> playerList;
int ROUNDS = 20; 
int counter = 4;
int gameListPosition = 0;

PImage bg;
PImage green;
PImage red;
PImage blue;
PImage yellow;

int startTime;
int timeOut;

void setup()
{
  gameList = new ArrayList<Integer>();
  
  for (int i = 0; i < ROUNDS; i++)
  {
      gameList.add(int(random(1, 5)));
  }
  
  size(685, 565);
  bg = loadImage("img/Simon.png");

  green = loadImage("img/green.png");
  red = loadImage("img/red.png");
  blue = loadImage("img/blue.png");
  yellow = loadImage("img/yellow.png");

  startTime = millis();
  timeOut = millis() + 1000;
}

void draw()
{
  background(bg);

  if (!isPlayerReady)
  {
    if (millis() >= timeOut)
    {
      int tone = gameList.get(gameListPosition);
      gameListPosition++;

      if (tone == 1)
      {
        image(green, 90, 30);
      }
      else if (tone == 2)
      {
        image(red, 325, 30);
      }
      else if (tone == 3)
      {
        image(yellow, 90, 260);
      }
      else if (tone == 4)
      {
        image(blue, 325, 260);
      }
      
      if (gameListPosition == counter)
      {
          isPlayerReady = !isPlayerReady;
      }
      
      timeOut = millis() + 1000;

    }
  }

```

Has somebody any hints to show the images a few seconds longer?

---

<div class="post-metadata">

**Author:** ![tony](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tony/32/949_2.png) [@tony](https://discourse.processing.org/u/tony)\
**Post date:** [June 7, 2020, 1:46am UTC](https://discourse.processing.org/t/blinking-images-are-too-fast/21632/2 "2020-06-07T01:46:33Z")

</div>

> [@SaltyBoy](#):
>
> ```auto
> timeOut = millis() + 1000;
> 
> ```

Whats going on at this line?

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 7, 2020, 2:00am UTC](https://discourse.processing.org/t/blinking-images-are-too-fast/21632/4 "2020-06-07T02:00:31Z")

</div>

Take at look at this example:

```auto
//State Changes

int startTime;
int timeOut;
int count;
int bg;

boolean state = false;

void setup()
  {
  size(200, 200);
  startTime = millis();
  timeOut = millis() + 5000;
  }

void draw()
  {
  background(bg);
  if (millis() >= timeOut)
    {
    timeOut = millis() + 5000;
    println(count++);
    state = true;
    }
    
   if (state)
     {
     bg = int(random(0, 255));
     state = false;  
     }
  }

```

`:)`

---

<div class="post-metadata">

**Author:** ![SaltyBoy](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SaltyBoy](https://discourse.processing.org/u/SaltyBoy)\
**Post date:** [June 7, 2020, 5:17am UTC](https://discourse.processing.org/t/blinking-images-are-too-fast/21632/5 "2020-06-07T05:17:44Z")

</div>

In this line the timeOut will be increased with a new time limit, because of the condition if (millis() \>= timeOut).

---

<div class="post-metadata">

**Author:** ![SaltyBoy](https://avatars.discourse-cdn.com/v4/letter/s/e99b99/32.png) [@SaltyBoy](https://discourse.processing.org/u/SaltyBoy)\
**Post date:** [June 7, 2020, 5:21am UTC](https://discourse.processing.org/t/blinking-images-are-too-fast/21632/6 "2020-06-07T05:21:34Z")

</div>

Thank you in advance! 🙂 If I have still any problems I let you know. I will test your code and I hope, this will work for images as well.
