Bounce noise

I am wondering if there is any way that I can make let’s say a bouncy noise when the ball hits one of the walls.

Here’s the code if have so far

function setup()
sound(SOUND_PICKUP, 2563)
x = WIDTH/2
y = HEIGHT/2
bc = color(37, 255, 0, 255)
tc = color(81, 133, 81, 255)
c = bc
inTouch = false
dx = 0
dy = 0
r = 30
end

function draw()

background(127, 127, 127, 255)
fill(c)
ellipse(x,y,r)
if inTouch then
    x = tx
    y = ty
    c = tc
else
    x = x +  dx
    y = y +  dy
    c = bc
end
if y > HEIGHT - r then
    dy = - dy
end
if y < r then
    dy = - dy
end
if x > WIDTH - r then
    dx = - dx
end
if x < r then
    dx = - dx
end

end

function touched(touch)
tx = touch.x
ty = touch.y
if touch.state == BEGAN then
inTouch = true
velocity = {}
sound(SOUND_PICKUP, 483)
end
if touch.state == MOVING then
table.insert(velocity,1,vec2(touch.deltaX,touch.deltaY))

end
if touch.state == ENDED then
    dx = 0
    dy = 0
    n = 0
    for i = 1,10 do
        if velocity[i] then
            n = n + 1
        dx = dx + velocity[i].x
        dy = dy + velocity[i].y
        
        end
    end
    if n >0 then
    dx = dx / n
    dy = dy / n
    end
    inTouch = false
    sound(SOUND_JUMP)
end

end
( sorry if the code doesn’t show properly, I’m new to this. )

It makes a sound once I pick it up, toss it, and when it starts. I would like it to make a noise when it hits one of the four walls.

Yep, it did not post properly. How can I make the code show up correctly?

I got it.


function setup()
    sound(SOUND_PICKUP, 2563)
    x = WIDTH/2
    y = HEIGHT/2
    bc = color(37, 255, 0, 255)
    tc = color(81, 133, 81, 255)
    c = bc
    inTouch = false
    dx = 0
    dy = 0
    r = 30
    end


function draw()

    background(127, 127, 127, 255)
    fill(c)
    ellipse(x,y,r)
    if inTouch then
        x = tx
        y = ty
        c = tc
    else
        x = x +  dx
        y = y +  dy
        c = bc
    end
    if y > HEIGHT - r then
        dy = - dy
    end
    if y < r then
        dy = - dy
    end
    if x > WIDTH - r then
        dx = - dx
    end
    if x < r then
        dx = - dx
    end
end

function touched(touch)
    tx = touch.x
    ty = touch.y
    if touch.state == BEGAN then
        inTouch = true
        velocity = {}
        sound(SOUND_PICKUP, 483)
    end
    if touch.state == MOVING then
        table.insert(velocity,1,vec2(touch.deltaX,touch.deltaY))
        
    end
    if touch.state == ENDED then
        dx = 0
        dy = 0
        n = 0
        for i = 1,10 do
            if velocity[i] then
                n = n + 1
            dx = dx + velocity[i].x
            dy = dy + velocity[i].y
            
            end
        end
        if n >0 then
        dx = dx / n
        dy = dy / n
        end
        inTouch = false
        sound(SOUND_JUMP)
    end
end