# Countdown and image moveDown() and random()

**URL:** <https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499>\
**Category:** Processing.py\
**Tags:** homework\
**Created:** [April 21, 2022, 2:44pm UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499 "2022-04-21T14:44:05Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![maya](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@maya](https://discourse.processing.org/u/maya)\
**Post date:** [April 21, 2022, 2:44pm UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499/1 "2022-04-21T14:44:05Z")

</div>

Hi there, I would like the countdown timer to disappear when it reaches 0, and at that point, only then the dog starts moving down, but right now the dog moves down at the beginning already. Also, there is only one dog instead of many. Any ideas as how I could solve this? Thanks 😃

```auto
add_library('sound')
add_library("sound")
ellX = 350 #initial dog position 
ellY = 0
countdown = 5 #beginning countdown

def setup():
    global sf, x, bgImage, y, speed, acceleration, countdown, dog 
    countdown = 5
    size(800, 600)
    frameRate(1)
    sf = SoundFile(this,"backgroundmusic.mp3")
    sf.play()
    bgImage = loadImage("backgroundimage.jpeg")
    dog = loadImage("dog.png")

def draw():
    global bgImage, x, y, dog, moveDown, ellX, ellY, ball, countdown
    image(bgImage, 0, 0, width, height)
    stroke(0, 255, 0)
    textSize(50)
    text(countdown, width/2, height/2)
    image(dog, ellX, ellY, 130, 50)
    
    if countdown > 0:
        countdown = countdown - 1
    if countdown == 0:
        moveDown = True
    else:
        noLoop()

    if moveDown == True:
        ellY = ellY + 4
    if ellY <= 650:
        moveDown = True 
    if ellY> 650:
        ellY = 0
        ellX = random (30, 570) #random placement 
        moveDown = True

```

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [April 21, 2022, 3:47pm UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499/2 "2022-04-21T15:47:51Z")

</div>

You already have a if-statement to show or not to show your countdown, namely `if countdown > 0 :` If you put `text(countdown, width/2, height/2)` in there it disappears when countdown reaches zero.

Dog moves because you change ellY straight away not after countdown reaches zero.

To have more dog you need data structure to store those dogs and easily refer to them. Array is most commonly used, but in python [dictionary](https://py.processing.org/reference/dictionary.html) might work as well

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [April 21, 2022, 9:17pm UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499/3 "2022-04-21T21:17:43Z")

</div>

To add to what @SomeOne has said –

You might employ a _list_ of dictionaries:

```python
dogs = [] # an empty list to hold the dogs

def setup():
    global dogs
    size(500, 500)
    # create a dictionary for the first dog
    first_dog = {'x':350, 'y':0, 'size':50}
    # add the first dog to the dogs list
    dogs.append(first_dog)

def draw():
    # render and increment the y-value of every dog in the list
    for dog in dogs:
        circle(dog['x'], dog['y'], dog['size'])
        dog['y'] += 1

def mouseClicked():
    # each mouse-click, add a dog with a randomized x-value to the list
    global dogs
    dogs.append({'x':random(width), 'y':0, 'size':50})

```

Note that the list will grow endlessly, full of ‘dogs’ that have long since passed the bottom of the display window. Check the different _list methods_ in the [reference](https://py.processing.org/reference/) to remove the dogs that have expired.

---

<div class="post-metadata">

**Author:** ![maya](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@maya](https://discourse.processing.org/u/maya)\
**Post date:** [April 22, 2022, 2:58pm UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499/4 "2022-04-22T14:58:15Z")

</div>

Thank you, if I want to replace the ball, with a dog picture instead, do I use `dogs = loadImage("dog.png")`, but then it’s not a list anymore. How do I do this?

---

<div class="post-metadata">

**Author:** ![maya](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@maya](https://discourse.processing.org/u/maya)\
**Post date:** [April 22, 2022, 3:06pm UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499/5 "2022-04-22T15:06:09Z")

</div>

Thank you, but for the countdown, the countdown text (numbers) is still there. How do I make it disappear when it reaches 0? (meaning out of the frame)

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [April 22, 2022, 3:54pm UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499/6 "2022-04-22T15:54:11Z")

</div>

As I tried to say earlier if you put the text in if statement it will be shown only when countdown as larger than zero

```auto
    if countdown > 0:
        countdown = countdown - 1
        text(countdown, width/2, height/2)

```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [April 22, 2022, 7:49pm UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499/7 "2022-04-22T19:49:40Z")

</div>

I’m assuming the dog image is the same for every dog? So, something like –

```python
dogs = []

def setup():
    global dog_img, dogs
    size(500, 500)
    dog_img = loadImage('dog.png')
    first_dog = {'x':350, 'y':0}
    dogs.append(first_dog)

def draw():
    for dog in dogs:
        image(dog_img, dog['x'], dog['y'])
        dog['y'] += 1

```

---

<div class="post-metadata">

**Author:** ![maya](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@maya](https://discourse.processing.org/u/maya)\
**Post date:** [April 23, 2022, 2:47am UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499/8 "2022-04-23T02:47:31Z")

</div>

Got it! Thank you so much

---

<div class="post-metadata">

**Author:** ![maya](https://avatars.discourse-cdn.com/v4/letter/m/cab0a1/32.png) [@maya](https://discourse.processing.org/u/maya)\
**Post date:** [April 23, 2022, 2:51am UTC](https://discourse.processing.org/t/countdown-and-image-movedown-and-random/36499/9 "2022-04-23T02:51:53Z")

</div>

Got it! Thank you very much!
