Drawing the edges of a constellation

Assignment Help Python Programming
Reference no: EM133028233

CPSC 231 Introduction to Computer Science for Computer Science Majors - University of Calgary

Assignment: Constellations

Discussing the assignment requirements with others is a reasonable thing to do, and an excellent way to learn. However, the work you hand-in must ultimately be your work. This is essential for you to benefit from the learning experience, and for the instructors and TAs to grade you fairly. Handing in work that is not your original work, but is represented as such, is plagiarism and academic misconduct. Penalties for academic misconduct are outlined in the university calendar.

Here are some tips to avoid plagiarism in your programming assignments.

1. Cite all sources of code that you hand-in that are not your original work. You can put the citation into comments in your program. For example, if you find and use code found on a web site, include a comment that says, for example:
Use the complete URL so that the marker can check the source.

2. Citing sources avoids accusations of plagiarism and penalties for academic misconduct. However, you may still get a low grade if you submit code that is not primarily developed by yourself. Cited material should never be used to complete core assignment specifications. You can and should verify and code you are concerned with your instructor/TA before submission.

3. Discuss and share ideas with other programmers as much as you like, but make sure that when you write your code that it is your own. A good rule of thumb is to wait 20 minutes after talking with somebody before writing your code. If you exchange code with another student, write code while discussing it with a fellow student, or copy code from another person's screen, then this code is not yours.

4. Collaborative coding is strictly prohibited. Your assignment submission must be strictly your code. Discussing anything beyond assignment requirements and ideas is a strictly forbidden form of collaboration. This includes sharing code, discussing code itself, or modelling code after another student's algorithm. You can not use (even with citation) another student's code.

5. Making your code available, even passively, for others to copy, or potentially copy, is also plagiarism.

6. We will be looking for plagiarism in all code submissions, possibly using automated software designed for the task. For example, see Measures of Software Similarity (MOSS - https://theory.stanford.edu/~aiken/moss/).

7. Remember, if you are having trouble with an assignment, it is always better to go to your TA and/or instructor to get help than it is to plagiarize. A common penalty is an F on a plagiarized assignment.

Goal
Writing a program with files, exceptions, command line arguments, and data structures.

Description
In this assignment, you will create a program that plots stars and constellations from input files. The following is an example from using stars_named_big_dipper.dat as a stars_location_file and BigDipper.dat as the only constellation file. (additionally drawing names has been triggered by -names)

The stars-location-file will be entered via a command-line argument. However, there will be a secondary optional mode where a filename may be entered via a user prompt for input if no filename was given as an argument.

Use os.path.isfile(filename) to determine if an entered filename is legitimate. Loop requesting additional filename inputs until filenames (for stars-location-file or constellation file) return True or "" is entered to exit the loop. At this point onward, if you have any issue opening a file to read it, or with the internal format of either the stars-location-file or constellation file you should exit the program with a descriptive error message. sys.exit(1) can be used for exiting the program at a specific point with error code 1. Or sys.exit("message").

You can expect every star named in a constellation file to exist in the stars-location-file. All (x, y) coordinates and the magnitude for stars will be floating-point values. The background colour should be black; the axes should be drawn in blue, the named stars in white, and the un-named stars in grey. The constellation edges will be drawn in red, green, or yellow. Each new constellation will be drawing using a different one of these colours. Once all 3 colours have been used, the next constellation will cycle back to use the first colour again.

Completing this assignment will require the use of system arguments, file input, functions, data structures, error handling, loops, and if statements. You will have to write the complete program yourself for this assignment. Global variables are explicitly not allowed (global constants are expected), so you must have a main function, and you must pass all the information you need in and out of the functions using parameters and returned values. The only variables allowed outside of functions are your constants. All of your functions must be properly documented with a description, parameter information, and return information.

Setup Stage

You must use this setup function to create your original window. Not using this setup function will result in lost marks. The WIDTH and HEIGHT constants should be 666666, 666666 and the BACKGROUND_COLOUR constant should be "black".

def setup(): turtle.bgcolor(BACKGROUND_COLOR) turtle.setup(WIDTH, HEIGHT, 0, 0) screen = turtle.getscreen() screen.delay(delay=0)
screen.setworldcoordinates(0, 0, WIDTH, HEIGHT) pointer = turtle
pointer.hideturtle() pointer.speed(0) pointer.up()
return pointer

You are not allowed to have any code outside functions, except for import statements, and constants. The only exception is the call to your main function, so you must also have a main function. Moreover, you are not allowed to use global variables unless they are constants. You should only need to import sys and turtle libraries. Your main function should deal with your system arguments, call your setup function to get your turtle pointer, and then call other functions that perform the reading of your input files and the drawing of the required information. You are free to use as many functions as you decide; however, there is a minimum required. You are expected to have at least:

1. A main function that handles the input

2. A function that reads an input file and returns a data structure with star information (a list of star lists (or tuples) and dictionary with names as keys and star lists (or tuples) as values is recommended)

3. A function that draws your axes.

4. A function that draws your stars and possibly draws the names of the named stars

5. A function that reads a constellation file and returns the constellation name, and a list of edges which are easiest to store as lists (or tuples) of stars names.

6. A function that draws a constellation given its name, edges, and the dictionary of star lists (or tuples) stored by name.

7. Any additional functions you may need for the bonus; if you decide to solve the bonus. You must implement the bonus using additional functions. You may call the additional functions from existing functions, but you may not change the existing functions to solve the bonus.

Command-line Arguments

You should check the command-line arguments (stored in sys.argv) as described earlier in this document in your main function, or a function called from your main function. If there is an error in the command- line arguments, your program should print a descriptive message and exit. Your program should only draw something if your arguments are correct, and the star information can be loaded from the given filename. It is recommended that you don't solve the rest of the assignment (reading the input files and drawing) until you have correctly implemented the command-line argument handling as described earlier in the assignment.

Read Star Information
This should be accomplished within a function. This function can make use of others if you like, but can also be self-contained.

If the information in the star filename is of the wrong type or doesn't have the required amount of entries separated by commas, you should print a descriptive error and exit. Remember to use try/except blocks to catch any errors during the process of opening/closing a file, and while reading the star information.

You should be able to use string.split(delimiter) to split the star information, and then the names into lists of strings. Remember, you only need the (x,y) information and magnitude for a star which can be stored as a list [x,y,mag,names] (or tuple (x,y,mag,names)).

You will want to return a list of all these lists (or tuples) to your main function. You will also want to return a dictionary that stores a list (or tuple) of star information as a value using the name of the star as a key. This information will help the constellation drawing function access the location information of the stars that define the endpoints of constellation edges.

Your star reading function should print the following information for every named star in the input file. Information about un-named stars should not be printed:

NAME is at (x,y) with magnitude mag
Ex.
ALPHERATZ is at (0.873265,0.031968) with magnitude 2.07 CAPH is at (0.512379,0.020508) with magnitude 2.28 ...
...

Drawing the Axes

This should be accomplished within a function. This function can make use of others if you like, but can also be self-contained.

Your program should draw the axes in blue. When you draw the axes, they must be oriented so that the centre of the Cartesian coordinate system (0, 0) is at the center of the screen (300, 300). The star coordinates will be given such that the x and y values are between -1 and 1. The screen height is 600 pixels. Therefore, each unit in the Cartesian coordinate system must be represented by 300 pixels. Both axes will go from -1 to +1. The step size for the axis ticks will be 0.25. For example, the x-axis would be labeled with -1.00, -0.75, -0.50, -0.25, 0.00, 0.25, 0.50, 0.75, 1.00.

Your set of axes should include a tick mark and a label for each unit (you can optionally omit the 0s at the origin for a cleaner look). While it is possible to create the axes using a (long) sequence of function calls alone, you must use loops appropriately to keep the total number of lines of code to a more reasonable amount. Draw your axes in blue on a black background created by the setup() function so that the constellations will be easy to see when drawn on top of them.

Drawing the Stars
This should be accomplished within a function. This function can make use of others if you like, but can also be self-contained.
Your program should draw every star in the input file. Each star without a name should be drawn in "grey" and every named star in "white". You should be able to do this by looping through your list of stars returned from your star information reading function. Draw every star in "grey", then loop through all the keys in your named star information dictionary and draw them in "white". If the user has given the argument to write the name of a star you can write it using
pointer.write(name,font=("Arial", 5, "normal"))
this should keep it small enough.
Each star should be drawn as a circle. To get the radius of the circle, you can use
diameter = 10 / (magnitude + 2) you will also want to use pointer.dot(diameter)
to draw your stars as filled circles.

Reading a Constellation File
Reading the constellation file should be accomplished within a function. This function can make use of others if you like, but can also be self-contained.

When the drawing of stars is complete, your program will enter a loop prompting the user for a valid constellation file from which it can read constellation information. This loop should exit only when the user enters "", or if the contents of the input file are incorrect. If the user gives a filename such that
os.path.isfile(filename) == False
the program should continue re-prompting for a valid filename.
If the information in the file doesn't have the required amount of entries separated by commas, you should print a descriptive error and exit. Remember to use try/except blocks to catch any errors during the process of opening/closing a file, and while reading the constellation information.
You should be able to use string.split(delimiter) to split the constellation information. Remember, the first line of the file is the constellation name, and the remaining lines are pairs of named stars. Each of these lines represents a single constellation edge. The information for an edge can be easily stored as a list [star_name1,star_name2] (or tuple (star_name1,star_name2)).
You will want to return a list of all these lists (or tuples) to your main function. You will also want to return the constellation name.
Your constellation reading function should print the following to the console for every constellation read: the name of the constellation and every star named in its edges. No star name should be printed more than once.
Ex.
Enter a constellations file (Ex. BigDipper.dat): BigDipper.dat
BIG DIPPER constellation contains {'MEGREZ', 'ALIOTH', 'MIZAR', 'MERAK', 'DUBHE', 'BENETNASCH', 'PHECDA'}

Drawing the Constellation
Drawing the edges of a constellation should be accomplished within a function. This function can make use of others if you like, but can also be self-contained.
For each constellation, your function must loop through every pair of stars that constitute its edges. To draw an edge, you will need 4 values: an (x, y) coordinate for the start of the edge and an (x, y) coordinate for the end of the edge. To get these, you should look up the named star in the star information dictionary to get the list of [x, y, mag, names] (or tuple of (x, y, mag, names)) star information.

The colour of a constellation line will be either red, green, or yellow. Each constellation will have its edges drawn in one colour, and the next constellation will cycle to the next colour. You can look at Assignment 2 for an idea of how to use a counter to accomplish the cycling of constellation colours.

Additional Specifications:
Ensure that your program meets all the following requirements:

• You should have the class, your name, your tutorial, your student id, the date, and description at the top of your code file in comments. Marks are given for these.
• The code file should be CPSC231F21A3-<Name>.py (ex. Mine would be CPSC231F21A3- Hudson.py)
• Import the necessary libraries
• Use constants appropriately. Your TA may note one or two magic numbers as a comment, but more will result in lost marks.
• Use descriptive naming of variables. The use of variables that follow the math descriptions given is fine for those purposes.
• Use the correct colouring as requested.
• Use in-line comments to indicate blocks of code and describe decisions or complex expressions.
• You should comment your functions descriptively. (see Assignment 2)
• Break and continue are generally considered bad form when learning to program. As a result, you are NOT allowed to use them when creating your solution to this assignment. In general, their use can be avoided by using a combination of if statements and writing better conditions on your while loops. You are allowed to use return within a loop inside a function, or sys.exit(1) in a loop of a function when finding an error to exit.
• You will have to perform error checking when reading an input file. Your program should never crash with a Python error. All errors should be avoided by checking if the file exists before opening it or caught by try/except structures if there is an error in a file. Descriptive messages should be produced instead of errors.

Bonus:
Looking for an A+? Improve the program so that each constellation has a box drawn around it. This box should contain within it every edge and star drawn. You can use padding, such as 5 pixels, to make the box slightly bigger than the constellation inside of it. Draw the constellation name (obtained from the constellation file) next to the box. Use a different colour that can be seen easily (such as orange) to differentiate this box from constellations/stars/axes. (Hint: you will need to track the largest and smallest x and y coordinates for each constellation, and then use these 4 values to draw a box around the constellations.). Write the min x, max x, min y, max y that define this box out to file <Name>_box.dat where <Name> is the name of the constellation as written at the top of its corresponding input file.

Each time a new constellation is run, you must indicate (by printing to terminal) if the new constellation bounding box (without the padding) overlaps prior drawn constellation bounding boxes (without the padding). Here Big Dipper was drawn, then Bootes, Hydra, Ursa Major. So on Hydra being drawn third the program would write to terminal only "Constellations HYDRA and BOOTES overlap!". However, when Usra Major is drawn last, then "Constellations URSA MAJOR and BIG DIPPER overlap!" and "Constellations URSA MAJOR and HYDRA overlap!".

This assignment will be graded on a combination of functionality and style. A base grade will be determined from the general level of functionality of the program (Does it handle arguments correctly? Does it read input files correctly? Does it draw correctly? Does it print the requested output correctly?). The base grade will be recorded as a mark out of 12.

The assignment will be graded out of 12, with the grade based on the program's level of functionality and conformance to the specifications. The program must not have syntax errors to get more than an F. A program with runtime errors that occur during proper usage of the program, every time it runs, will not get better than a C grade. Runtime errors are your program crashing.

Attachment:- Introduction to Computer Science.rar

Reference no: EM133028233

Questions Cloud

What is the significance of the fact that the process : What is the significance of the fact that the process has continued essentially unchanged for so many years? What does this fact suggest about the people in the
Model of governance in the philippines : Legeslative and judiciary which among the following doctrines best describes the model of governance in the Philippines?
How much would you get for it : Question - A dealer is quoting a bid discount of 0.75 and an ask discount of 0.73 on a T-Bill with a maturity of 125 days. How much would you get for it
What amount of short-term cash reserves : You wish to carry at least twenty days cash on hand. If annual budgeted cash expenses are $48,000,000, what amount of short-term cash reserves should targeted
Drawing the edges of a constellation : Drawing the edges of a constellation should be accomplished within a function. This function can make use of others if you like, but can also be self-contained
What types are protected : Not all forms of strikes are protected by the NLRA. Answer the following questions:
What was cost of goods sold for the year : During 2013, the company incurred operating expenses of $40,000 and interest expenses of $60,000. What was Cost of Goods Sold for the year
Calculate the copy department costs : The Paver Company's copy department, which does almost all of the photocopying for the sales department and the administrative department, budgets the following
Journalise the adjusting entries at oct on the book : The total amount of cheques still outstanding at 31 october amounted to $2310. Journalise the adjusting entries at Oct 31 on the book of ATO Ltd

Reviews

len3028233

11/12/2021 11:51:55 PM

This is an assignment in Python. Please READ the assignment description CAREFULLY, and don''''t use too advanced code or method in this assignment. Because this is an assignment for python beginners. There are a lot of input files for this assignment, I will pass them to you later. Dont forget to add comments in the code

Write a Review

Python Programming Questions & Answers

  Program to convert mile-to-kilometers or kilometers-to-mile

Write program that prompts the user to select either Miles-to-Kilometers or Kilometers-to-Miles, then asks the user to enter the distance they wish to convert.

  Find the plant by the name passed in as an argument

An online plant distributor has recently experience a shortage in its supply of Anemone plants such that the price has increased by 20%.

  Compare the values of adding the numbers to multiplying

Compare the values of adding the numbers to multiplying 1/2 and 1/3 times the number of times they were added.

  Calculate the cost of that order and add

A good friend of yours is managing a fund raiser for a football team. He needs a program to calculate the total amount of candy sold at a football game.

  Display the stripped phone number

Ask the user to enter the 4-digit code of an orange. Strip all the leading and trailing whitespace characters from the code. Display the stripped phone number.

  Write a function the amount of loan at the start

Assignment Question - Task: Loan. Write a function loan_amount_left that takes in four inputs. The function returns the amount of loan left at the end of year

  Compute and display the charges for a patients hospital stay

Write a program that computes and displays the charges for a patient's hospital stay. First, the program should ask patient name and if the patient was admitted

  Write python program isosceles tri equilateral tri rectangle

Write python program Isosceles Tri Equilateral Tri Rectangle, Write another "driver" script called project1.py which imports the polygon.py module, reads an input file of polygonal data and writes another file of areas and perimeters.

  CITS1401 Computational Thinking with Python Assignment

CITS1401 Computational Thinking with Python Assignment Help and Solution, The University of Western Australia. Project - Finding Synonyms by Association

  Calculate the total displacement of the system of springs

Calculate the total displacement of the system of springs - You are free to use any linear system solver from chapter 6, including the solvers that are part of the SciPy and/or numpy packages.

  Demonstrate the use of nested function calls

Add a function named clear_screen that uses a combination of the functions nine_lines, three_lines, and new_line.

  Calculate the average weights of people

Calculate the average weights of people whose names begin with the letter specified in the config parameter. Write the definition of the function avg_weight.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd