Ball doesn't appear

Hi, for some reason, the ball in my code doesn’t show up. Do you know why?

add_library('sound')
import sys
count = 0 
ball = 0
countdown = 6 
dogs = [] 

def setup():
    global sf, x, bgImage, y, speed, acceleration, countdown, dogs, dog_img
    countdown = 6
    x, y = -50, -50
    speed = 2
    acceleration = 0.4
    size(800, 600)
    frameRate(1)
    sf = SoundFile(this,"backgroundmusic.mp3")
    sf.play()
    bgImage = loadImage("backgroundimage.jpeg")
    dog_img = loadImage("dog.png")
    first_dog = {'x':350, 'y':0} 
    dogs.append(first_dog) 


def draw():
    global bgImage, x, y, speed, dogs, count, ball, countdown, acceleration
    image(bgImage, 0, 0, width, height)
    textSize(50)
    
    if countdown > 0:
        countdown = countdown - 1
        text(countdown, width/2, height/2)
    if countdown == 0:
        for dog in dogs:
            image(dog_img, dog['x'], dog['y'])
            dog['y'] += 50
        dogs.append({'x':random(height), 'y':0})

    textSize(30)
    text("Score:", count, 40, 550)

    ellipse(x, y, 50, 50)
    y = y + speed
    speed = speed + acceleration
    if y > height:
        speed = speed * -1
        y = height
        
def mouseReleased():
    global x, y, speed
    x = mouseX
    y = mouseY
    speed = 1
        
    if count > 10:
        text("You won!", 100, 100)
        text("Press a key to exit", 50, 100)
        sys.exit()
        if count < 10:
            text("You lost!", 100, 100)
            text("Press a key to exit", 50, 100)
            sys.exit()

For ellipse and all 2d shapes (rect, line, arc etc), you need to define a colour either for fill or stroke. Fill sets colour for filling the shape and stroke sets outline. As with all colour setting in processing in colorMode() defines how processing will interpret given values.
Keep in mind that setting fill() or stroke() may effect text colour too.

I assume the ball is rendered using the ellipse() line? Have you checked the x-y coord values? Perhaps insert a print() line to test –

    ...
    print(x, y)  # do you see the values you expect in the console?
    ellipse(x, y, 50, 50)
    ...
1 Like