Question

In: Computer Science

Create a new program, called stars.py, for (eventually) drawing a 500x500 pixel picture of the night...

Create a new program, called stars.py, for (eventually) drawing a 500x500 pixel picture of the night sky. The stars.py file 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:
    1. Split star string into smaller strings
    2. grab the x coordinate and convert it into a float
    3. calculate the pixel coordinate with the formula: 250 + (250 * x)
    4. 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:
    1. Split star string into smaller strings
    2. grab the y coordinate and convert it into a float
    3. calculate the pixel coordinate with the formula: 250 - (250 * y)
    4. 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") → ""

Solutions

Expert Solution

#the following code may throw an error in python2

#drop a comment if something is wrong. check for typos in the function names

#---------------------------------------

def getStarPixelX(a):

    #splits the given string into a list

    a=a.split(",")

    # applies the given formula on the x cordinate

    x=250+(250*float(a[0]))

    return x

print(getStarPixelX("0.0,1.0,0.0,1,-1.5,1"), getStarPixelX("0.5,-0.5,0.0,2,2.0,2"))

def getStarPixelY(a):

    #splits the given string into a list

    a=a.split(",")

    #applies the given formula on the Y cordinate

    y=250-(250*float(a[1]))

    return y

print(getStarPixelY("0.0,1.0,0.0,1,-1.5,1"),getStarPixelY("0.5,-0.5,0.0,2,2.0,2"))

def getStarSize(a):

    #splits the given string into a list

    a=a.split(",")

    #applies the given formula on the magnitude

    size=10.0/(float(a[4])+2)

    return size

print(getStarSize("0.0,1.0,0.0,1,-1.5,1"),

getStarSize("0.5,-0.5,0.0,2,2.0,2"))

def getStarName(a):

    #splits the given string into a list

    a=a.split(",")

    # if te length of the list is 7

    if len(a)==7:

        #return the last element of the list

        return a[-1]

    else:       

        return ""

print(getStarName("0.5,-0.5,0.0,2,2.0,2"),getStarName("0.0,1.0,0.0,1,-1.5,1,BOB"))

#-------------------------OUTPUT---------------------------------------------------

250.0 375.0

0.0 375.0

20.0 2.5

BOB


Related Solutions

Assembly language program create a program that outputs a picture that represents halloween in ASCll art...
Assembly language program create a program that outputs a picture that represents halloween in ASCll art (jack-o-lantern, witch's hat, etc)
Create a program in JAVA that displays a design or picture for someone in your quarantine...
Create a program in JAVA that displays a design or picture for someone in your quarantine household/group: a pet, a parent, a sibling, a friend. Make them a picture using the tools in TurtleGraphics and run your program to share it with them! Use a pen object, as well as any of the shape class objects to help you create your design. You must use and draw at least 5 shape objects. - You must use a minimum of 4...
Objective: CODE IN JAVA Create a program that displays a design or picture for someone in...
Objective: CODE IN JAVA Create a program that displays a design or picture for someone in your quarantine household/group: a pet, a parent, a sibling, a friend. Make them a picture using the tools in TurtleGraphics and run your program to share it with them! Use a pen object, as well as any of the shape class objects to help you create your design. You must use and draw at least 5 shape objects. You must use a minimum of...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a...
2. Create a new NetBeans project called PS1Gradebook. Your program will simulate the design of a student gradebook using a two-dimensional array. It should allow the user to enter the number of students and the number of assignments they wish to enter grades for. This input should be used in defining the two-dimensional array for your program. For example, if I say I want to enter grades for 4 students and 5 assignments, your program should define a 4 X...
Create a JavaFX program in java that does the following items: Display a drawing area of...
Create a JavaFX program in java that does the following items: Display a drawing area of dimension 500 x 400, with a black background. Provides a radio button group to allow the user to select one of the following three colors: red, green, and blue. Upon startup, the red radio button should be selected. Each time the user clicks in the drawing area, a circle of size 10 of the color selected by the radio button group in item 2...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama...
Problem 1 Create a new project called Lab7 Create a class in that project called ListORama Write a static method in that class called makeLists that takes no parameters and returns no value In makeLists, create an ArrayList object called avengers that can hold String objects. Problem 2 Add the following names to the avengers list, one at a time: Chris, Robert, Scarlett, Clark, Jeremy, Gwyneth, Mark Print the avengers object. You will notice that the contents are displayed in...
Objective: Create a program that displays a design or picture for someone in your quarantine household/group:...
Objective: Create a program that displays a design or picture for someone in your quarantine household/group: a pet, a parent, a sibling, a friend. Make them a picture using the tools in TurtleGraphics and run your program to share it with them! Use a pen object, as well as any of the shape class objects to help you create your design. You must use and draw at least 5 shape objects. You must use a minimum of 4 different colors...
Create a java program that will do the following: Create a method called getInt.Allow the user...
Create a java program that will do the following: Create a method called getInt.Allow the user to enter up to 20 student names,and for each student 3 quiz scores (in the range 0-100). Once input is done, display each student’s name, their three quiz scores, and their quiz score average, one student per line. The output table does not need to line up perfectly in columns.Use dialog boxes for all input and output.Use the method to input the three scores.Parameter...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
1. create a class called ArrayStack that is a generic class. Create a main program to...
1. create a class called ArrayStack that is a generic class. Create a main program to read in one input file and print out the file in reverse order by pushing each item on the stack and popping each item off to print it. The two input files are: tinyTale.txt and numbers.txt. Rules: You cannot inherit the StackofStrings class. 2. Using your new ArrayStack, create a new class called RArrayStack. To do this, you need a) remove the capacity parameter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT