bola que rebota una con otra python

 r = 20

x = [100, 300]

y = [200, 200]

vx = [2, -3]

vy = [3, -2]


def setup():

    size(400, 400)


def draw():

    background(255)

    

    for i in range(2):


        x[i] += vx[i]

        y[i] += vy[i]


        if x[i] < r or x[i] > width - r:

            vx[i] *= -1

        if y[i] < r or y[i] > height - r:

            vy[i] *= -1



    dx = x[1] - x[0]

    dy = y[1] - y[0]

    

    dist = sqrt(dx*dx + dy*dy)

    

    if dist < r * 2:

        vx[0] *= -1

        vy[0] *= -1

        vx[1] *= -1

        vy[1] *= -1



    for i in range(2):

        ellipse(x[i], y[i], r*2, r*2)


Comentarios

Entradas populares de este blog

5)Peligros de red

Coches que se chocan con una bola