# Starmap - plot a file of star coordinates # # This program plots a field of stars from the stars.txt taken from # http://nifty.stanford.edu/2009/reid-starmap/ # from myro import * #Opens the specified file and reads in the X and Y coordinates of each star #Returns a list of tuples with the X and Y coordinates. def readStarData(filename): starList = [] myFile = open(filename, "r") starData = myFile.readlines() print "length of starData is:", len(starData) for starLine in starData: tempList = starLine.split() xStr = tempList[0] yStr = tempList[1] x = float( xStr) y = float( yStr) starTuple = (x,y) starList.append( starTuple ) return( starList) # Creates a graphWindow and draws all stars into it. Stars in the starData # parameter are assumed to be in the format generated by the readStarData # function (above) def plotStarData(starData, winSize): myWin = GraphWin("StarMap", winSize,winSize) #If you remove this line, you have to use #the manual conversion that is commented out #below myWin.setCoords(-1.0 , 1.0, 1.0, -1.0) myWin.setBackground( color_rgb(0,0,0) ) for star in starData: X = star[0] Y = star[1] #This will convert coordinate spaces #If you don't set the -1,1, and 1,-1 coordinate #space for the GraphWin up above: # #halfWinSize = winSize / 2.0 #wx = (halfWinSize * X) + halfWinSize #wy = (halfWinSize * Y) + halfWinSize #point = Point(wx,wy) point = Point(X,Y) point.setFill( color_rgb(255,255,255)) point.draw(myWin) print "All finished plotting stars!" #To draw a star map, you have to do two things: #First, read the data: myStarList = readStarData("stars.txt") #Then, plot the data! plotStarData( myStarList,700)