The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 314 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
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 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 make sure it is working correctly. Once the function is completed, submit it to the corresponding star_project drop box. It is OK if your stars.py file has other stuff in it, just make sure it includes the required function(s), and it does not crash.
Â
get_star_pixel_x()
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.)
get_star_pixel_y()
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.)
get_star_size()
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.)
get_star_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.)
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()
draw_star()
Draw the rectangle using the code below:canvas.create_rectangle(left_x, top_y, right_x, bottom_y, fill="white", width=0)
Below are some example function calls that draw stars.
draw_all_stars()
Below is the example function call.
get_star_string()
Below are example function calls.
draw_star_by_name()
Below are example function calls.
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.
draw_constellation_line()
Draw the line using the following code:canvas.create_line(x1, y1, x2, y2, fill="yellow")
Below is an example function call.
draw_constellation_file()
Below is an example function call.
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
draw_all_stars()
draw_constellation_file("BigDipper_lines.txt")
draw_constellation_file("Bootes_lines.txt")
draw_constellation_file("Cas_lines.txt")
draw_constellation_file("Cyg_lines.txt")
draw_constellation_file("Gemini_lines.txt")
draw_constellation_file("Hydra_lines.txt")
draw_constellation_file("UrsaMajor_lines.txt")
draw_constellation_file("UrsaMinor_lines.txt")
#complete drawing the canvas
mainloop()
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly