In: Computer Science
Create a new program, called stars.py, for (eventually) drawing a 500x500 pixel picture of the night sky. The stars.py file will define several custom functions. You should write each function and then test it to verify it is working correctly. Make sure you match each function name precisely. Once complete submit it to D2L.
getStarPixelX()
Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)
getStarPixelY()
Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)
getStarSize()
Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)
getStarName()
Below are some example function calls and return values. You should test them by having your program call the function and print out the return value. (You can erase your test code later.)
#the following code may throw an error in python2
#drop a comment if something is wrong. check for typos in the function names
#---------------------------------------
def getStarPixelX(a):
#splits the given string into a list
a=a.split(",")
# applies the given formula on the x cordinate
x=250+(250*float(a[0]))
return x
print(getStarPixelX("0.0,1.0,0.0,1,-1.5,1"), getStarPixelX("0.5,-0.5,0.0,2,2.0,2"))
def getStarPixelY(a):
#splits the given string into a list
a=a.split(",")
#applies the given formula on the Y cordinate
y=250-(250*float(a[1]))
return y
print(getStarPixelY("0.0,1.0,0.0,1,-1.5,1"),getStarPixelY("0.5,-0.5,0.0,2,2.0,2"))
def getStarSize(a):
#splits the given string into a list
a=a.split(",")
#applies the given formula on the magnitude
size=10.0/(float(a[4])+2)
return size
print(getStarSize("0.0,1.0,0.0,1,-1.5,1"),
getStarSize("0.5,-0.5,0.0,2,2.0,2"))
def getStarName(a):
#splits the given string into a list
a=a.split(",")
# if te length of the list is 7
if len(a)==7:
#return the last element of the list
return a[-1]
else:
return ""
print(getStarName("0.5,-0.5,0.0,2,2.0,2"),getStarName("0.0,1.0,0.0,1,-1.5,1,BOB"))
#-------------------------OUTPUT---------------------------------------------------
250.0 375.0
0.0 375.0
20.0 2.5
BOB