can someone help how to make this code for bouncing ball with gravity, I already make the ball

Viewed 33

This is the lib

import numpy as np
from matplotlib import pyplot as plt

This is the user entries

print("The scale is arranged in a way that 1 pixel relates to 1 cm of real space.")
print("")
print("You can decide the width and the height of the field in cm, e.g. 1000 1000.")
col, row = input("Enter the width and the height of the field in cm: ").split()
col = int(col)
row = int(row)
print("")
print("You can decide the ball's initial position (x,y) in cm, e.g. 100 100.")
a, b = input("Enter the ball's initial position (x,y) in cm: ").split()
a = int(a)
b = int(b)

print("")
print("You can decide the ball's diameter in cm, e.g. 50.")
pd = input("Enter the ball's diameter in cm: ")
pd = int(pd)
print("")

plt.figure(figsize=(4, 4), dpi=200)

size screen

col = col
row = row

Template 2D screen

Screen_2D = np.zeros(shape=(row, col, 3), dtype=np.uint8)

variables for drawing ball

hd = round(pd / 2)

drawing ball

for j in range(a - hd, a + hd):
    for i in range(b - hd, b + hd):
        if ((i - a) ** 2 + (j - b) ** 2) < hd ** 2:
            Screen_2D[j, i, 2] = 255

I hope you help me for this

0 Answers
Related