Last active
November 1, 2018 15:49
-
-
Save HariSan1/8f26ccdad6f511517b60238333af0e3a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#TSB - Use our own previously created module in Python - rocket positions (x,y) | |
import matplotlib.pyplot as plt | |
import simple_module1 as rg | |
#Make a series of rockets | |
rockets=[] | |
rockets.append(rg.Rocket()) | |
rockets.append(rg.Rocket(0,2)) | |
rockets.append(rg.Rocket(1,4)) | |
rockets.append(rg.Rocket(2,6)) | |
rockets.append(rg.Rocket(3,7)) | |
rockets.append(rg.Rocket(5,9)) | |
rockets.append(rg.Rocket(8, 15)) | |
#Show where each rocket is | |
for index, rocket in enumerate(rockets): | |
#original position of rockets | |
print("Rocket %d is at (%d, %d)." % (index, rocket.x, rocket.y)) | |
plt.plot(rocket.x, rocket.y, 'rs', linewidth=2, linestyle='dashed', markersize=12) | |
#move the 'rocket' one up | |
rocket.move_up() | |
print("New Rocket position %d is at (%d, %d)." % (index, rocket.x, rocket.y)) | |
#plot the new position | |
plt.plot(rocket.x, rocket.y, 'bs', linewidth=2, linestyle='dashed', markersize=12) | |
#move the rocket left | |
rocket.move_left() | |
plt.plot(rocket.x, rocket.y, 'ys', linewidth=2, linestyle='dashed', markersize=12) | |
#show graph legend to match colors with position | |
plt.title("Positions from using Module") | |
plt.gca().legend(('original position','^ - Moved up', '< - Moved left')) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment