SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 314 Weeks Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 16 Dec 2017 My Price 10.00

project aims to build one big program that enables

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):

  1. The x coordinate of the star.
  2. The y coordinate of the star.
  3. The z coordinate of the star.
  4. The Henry Draper number, which is simply a unique identifier for the star.
  5. The magnitude or brightness of the star.
  6. The Harvard Revised number, another identifier.
  7. 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 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()

  • 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.)

  • get_star_pixel_x("0.0,1.0,0.0,1,-1.5,1") â 250.0
  • get_star_pixel_x("0.5,-0.5,0.0,2,2.0,2") â 375.0

get_star_pixel_y()

  • 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.)

  • get_star_pixel_y("0.0,1.0,0.0,1,-1.5,1") â 0.0
  • get_star_pixel_y("0.5,-0.5,0.0,2,2.0,2") â 375.0

get_star_size()

  • 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.)

  • get_star_size("0.0,1.0,0.0,1,-1.5,1") â 20.0
  • get_star_size("0.5,-0.5,0.0,2,2.0,2") â 2.5

get_star_name()

  • 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.)

  • get_star_name("0.0,1.0,0.0,1,-1.5,1,BOB") â "BOB"
  • get_star_name("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()

draw_star()

  • 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 left_x, top_y, right_x, bottom_y coordinates for the rectangle. (Hint: size/2)
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_star("0.0,0.0,0.0,1,-1.5,1")
  • draw_star("0.5,0.5,0.0,2,2.0,2")

draw_all_stars()

  • 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 draw_star() function.

Below is the example function call.

  • draw_all_stars()

get_star_string()

  • 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 get_star_name() function to see if the correct star string has been found.

Below are example function calls.

  • get_star_string("POLARIS") â "0.010128,0.007897,0.999918,8890,1.97,424,POLARIS"
  • get_star_string("BOB") â "" with printed error msg: "ERROR: No star called BOB could be found."

draw_star_by_name()

  • 1 Input Parameter: a star's name
  • No Return Value.
  • Hint: Just use the get_star_string() and draw_star() functions to draw the named star.

Below are example function calls.

  • draw_star_by_name("POLARIS")
  • draw_star_by_name("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

draw_constellation_line()

  • 2 Input Parameters: 2 different star names
  • No Return Value.
  • Steps:Get the star strings for each star using get_star_string()
  • Get the pixel x and y coordinates for each star using get_star_pixel_x() and get_star_pixel_y()
Draw the line using the following code:canvas.create_line(x1, y1, x2, y2, fill="yellow")

Below is an example function call.

  • draw_constellation_line("HYA BETA","HYA ALPHA")

draw_constellation_file()

  • 1 Input Parameter: A file name (File should be downloaded first.)
  • No Return Value.
  • Hint: Split each line by comma and call the draw_constellation_line() function.

Below is an example function call.

  • draw_constellation_file("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


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()

Answers

(5)
Status NEW Posted 16 Dec 2017 07:12 AM My Price 10.00

-----------  ----------- 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

Not Rated(0)