# Starter file for drawing a star chart from a series of data files # Uses Turtle Graphics for plotting from turtle import * # Size of overall star chart SIZE = 400 # Given original x and y coordinates in range [-1, 1], return coordinates # scaled to new size as a tuple def trans_coords_pixel(orig_x, orig_y, size): new_x = orig_x * size new_y = orig_y * size return (new_x, new_y) # Draw a star of a particular size at a given position, passed in as a tuple def draw_star(position, size): up() goto(position[0] - 1, position[1] - 1) down() fill(True) for i in range(4): right(90) forward(size) fill(False) # Reads a data file and returns a dictionary of star names such that # the key is a star name and the value is its Draper number def read_star_info(stars_file): star_names = {} for line in stars_file: line = line.strip().split() draper_no = line[3] if len(line) >= 7: names = "" for i in range(6, len(line)): names += line[i] + " " names = names.split(";") for name in names: star_names[name.strip()] = draper_no return star_names # Very simple example of a function that returns multiple values def person_data(): name = "Daffy" age = 10 salary = 50000 return name, age, salary bgcolor("black") color("white") # Draw some sample stars draw_star(trans_coords_pixel(.5, .5, SIZE), 2) draw_star(trans_coords_pixel(1, 1, SIZE), 2) draw_star(trans_coords_pixel(-1, -1, SIZE), 2) # Print out all star names found in file mapped to their Draper numbers stars_file = open("stars.txt") star_names = read_star_info(stars_file) print star_names # Example call on a function that returns multiple values p_name, p_age, salary = person_data() print p_age