Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

((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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

What other organizations compete on this issue?

Answered: 1 week ago

Question

Which of these influenced your life most dramatically?

Answered: 1 week ago

Question

What roles have these individuals played in your life?

Answered: 1 week ago