Question: ((The following code(python) works smoothly. I need to tell this code in the classroom. Can you tell how the code in each row works?)) Code:

((The following code(python) works smoothly. I need to tell this code in the classroom. Can you tell how the code in each row works?))

Code:

import matplotlib.pyplot as plt

import numpy as np

import matplotlib.animation as animation

basket = [0] #Acts as a flag if basket was made

Speed = 100 #Can be changed

distance = 800 #Can be changed

angle = 60 #Can be changed

#Degree to radian for angle

ux=Speed*np.cos(np.deg2rad(angle))

uy=Speed*np.sin(np.deg2rad(angle))

t1=0

s=0

elst=0.7

fig,ax=plt.subplots()

#Draws Basket Net

rectangle = plt.Rectangle((distance,200), -100, 100, fc='blue',ec="black")

plt.gca().add_patch(rectangle)

plt.axis('scaled')

#Draws Basket Pole

plt.axvline(x = distance, color = 'b', label = 'axvline - full height')

#Returns x, y for Trajectory

def traj(t):

global ux,uy,t1,s

y=uy*(t-t1)-.5*9.8*((t-t1)**2)

if y>0:

pass

elif y<0:

y=0

s += ux * (t - t1)

t1=t

uy=uy*elst

ux=ux*elst

x=s+ux*(t-t1)

return x,y

# for ground-line...

g = np.arange(-250, 2200, 1)

w=0*g

l = plt.plot(g,w)

# for Frame...

Frame=plt.axis([-250, 2200, -50, 550])

redDot, = plt.plot([0], [0], 'ro')

def animate(i):

x, y = traj(i)

if(x>=(distance-100) and x<=distance and y>=200 and y<=300 and basket[0]==0):

print("************************************ Congratulations!!! It's a basket | ************************************")

basket[0]=1

x, y = traj(i)

redDot.set_data(x,y)

return redDot,

# create animation using the animate() function

myAnimation = animation.FuncAnimation(fig, animate, interval=5, frames=np.arange(0.0, 100, .1), blit=True, repeat=False)

plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!