Question: Stars Project This project aims to build one big program that enables users to create star charts (pictures) from star catalog data files. The project
Stars Project
This project aims to build one big program that enables users to create star charts (pictures) from star catalog data files. The project is divided into multiple parts, where each part requires functions to be written and tested. All work should be done in a python file called stars.py. As the parts build on top of each other, it is imperative that each part be completed correctly.
The Big Picture
Download the stars.txt file and open it in notepad++. It is a comma separated file full of data on stars. Each line has the form:
0.010128,0.007897,0.999918,8890,1.97,424,POLARIS
Throughout this project, we will refer to this as a star string. Each star string contains the following items (bolded if used in this project):
The x coordinate of the star.
The y coordinate of the star.
The z coordinate of the star.
The Henry Draper number, which is simply a unique identifier for the star.
The magnitude or brightness of the star.
The Harvard Revised number, another identifier.
The common name (if it has a name)
The goal of the assignment is to produce the image below: 
In order to draw star charts, we must convert star coordinates used by astronomers into pixel point coordinates used by the python canvas. Star charts use a coordinate system with x and y ranging from -1 to 1. Pixel drawings, on the other hand, use a coordinate system that has 0,0 in the top left and extends to the maximum number of pixels per row and column. See the diagrams below:
| Star Point Coordinate System | Pixel Point Coordinate System |
![]() | ![]() |
Library of Functions
Create a new program, called stars.py, for (eventually) drawing a 500x500 pixel picture of the night sky. The stars.pyfile 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()
1 Input Parameter: a star string
Return: the x pixel coordinate of the star
Steps:
Split star string into smaller strings
grab the x coordinate and convert it into a float
calculate the pixel coordinate with the formula: 250 + (250 * x)
return the result
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.)
getStarPixelX("0.0,1.0,0.0,1,-1.5,1") ? 250.0
getStarPixelX("0.5,-0.5,0.0,2,2.0,2") ? 375.0
getStarPixelY()
1 Input Parameter: a star string
Return: the y pixel coordinate of the star
Steps:
Split star string into smaller strings
grab the y coordinate and convert it into a float
calculate the pixel coordinate with the formula: 250 - (250 * y)
return the result
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("0.0,1.0,0.0,1,-1.5,1") ? 0.0
getStarPixelY("0.5,-0.5,0.0,2,2.0,2") ? 375.0
getStarSize()
1 Input Parameter: a star string
Return: the pixel size of the star
Hint: The formula to convert a star's magnitude to its size is: 10.0/(magnitude + 2)
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("0.0,1.0,0.0,1,-1.5,1") ? 20.0
getStarSize("0.5,-0.5,0.0,2,2.0,2") ? 2.5
getStarName()
1 Input Parameter: a star string
Return: the name of the star if it has one, else the empty string ("")
Hint: If a star string has 7 values, then the last value is the star's name
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("0.0,1.0,0.0,1,-1.5,1,BOB") ? "BOB"
getStarName("0.5,-0.5,0.0,2,2.0,2") ? ""
Canvas Drawing Setup
As we begin drawing stars on a canvas, we need to make sure we have the correct drawing library. Please make sure you have the correct code at the top and bottom of your file.
# set up the graphics library. from Tkinter import * window = Tk() canvas = Canvas(window, width=500, height=500, background="black") canvas.pack() #All your code (including function definitions) goes here in the middle #complete drawing the canvas mainloop()
drawStar()
1 Input Parameter: a star string
No Return
Steps:
Get the pixel x, y, and size values for the star using the functions you previously defined.
Calculate the leftX, topY, rightX, bottomY coordinates for the rectangle. (Hint: size/2)
Draw the rectangle using the code below:
canvas.create_rectangle(leftX, topY, rightX, bottomY, fill="white", width=0)
Below are some example function calls that draw stars.
drawStar("0.0,0.0,0.0,1,-1.5,1")
drawStar("0.5,0.5,0.0,2,2.0,2")

drawAllStars()
No Input Parameters
No Return
Steps:
Open the file 'stars.txt' (Make sure you download it to the Desktop first.)
Split file into lines
For each line, call the drawStar() function.
Below is the example function call.
drawAllStars()

getStarString()
1 Input Parameter: a star's name
Return: the star string of the star with matching name in the file stars.txt. If no star with a matching name can be found, an error message should be printed and the empty string ("") should be returned.
Hint: Search the file line by line using the getStarName() function to see if the correct star string has been found.
Below are example function calls.
getStarString("POLARIS") ? "0.010128,0.007897,0.999918,8890,1.97,424,POLARIS"
getStarString("BOB") ? "" with printed error msg: "ERROR: No star called BOB could be found."
drawStarByName()
1 Input Parameter: a star's name
No Return Value.
Hint: Just use the getStarString() and drawStar() functions to draw the named star.
Below are example function calls.
drawStarByName("POLARIS")
drawStarByName("SIRIUS")

Constellations
Constellations are described by pairs of stars that are connected with yellow lines. Each constellation file has a pair of star names per line. Examine a constellation file before proceeding to the next section.
BigDipper_lines.txt
Bootes_lines.txt
Cas_lines.txt
Cyg_lines.txt
Gemini_lines.txt
Hydra_lines.txt
UrsaMajor_lines.txt
UrsaMinor_lines.txt
drawConstellationLine()
2 Input Parameters: 2 different star names
No Return Value.
Steps:
Get the star strings for each star using getStarString()
Get the pixel x and y coordinates for each star using getStarPixelX() and getStarPixelY()
Draw the line using the following code:
canvas.create_line(x1, y1, x2, y2, fill="yellow")
Below is an example function call.
drawConstellationLine("HYA BETA","HYA ALPHA")

drawConstellationFile()
1 Input Parameter: A file name (File should be downloaded first.)
No Return Value.
Hint: Split each line by comma and call the drawConstellationLine() function.
Below is an example function call.
drawConstellationFile("BigDipper_lines.txt")

Project Complete!
You can draw everything (assuming all functions are complete and the files are downloaded) with the code below:
# set up the graphics library. from Tkinter import * window = Tk() canvas = Canvas(window, width=500, height=500, background="black") canvas.pack() #All your code (including function definitions) goes here in the middle drawAllStars() drawConstellationFile("BigDipper_lines.txt") drawConstellationFile("Bootes_lines.txt") drawConstellationFile("Cas_lines.txt") drawConstellationFile("Cyg_lines.txt") drawConstellationFile("Gemini_lines.txt") drawConstellationFile("Hydra_lines.txt") drawConstellationFile("UrsaMajor_lines.txt") drawConstellationFile("UrsaMinor_lines.txt") #complete drawing the canvas mainloop() 
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts


