Question: help me out with python! Assignment Goals The goals of this assignment are: Make sure you are setup with Python and PyCharm Practice writing a
help me out with python!
Assignment Goals
The goals of this assignment are:
- Make sure you are setup with Python and PyCharm
- Practice writing a small program
- Use functions, loops, and import
Getting Started
Note, this assignment builds on the Lab 1 exercise. While you can read over this assignment, it is best to finish Lab 1 before starting this assignment.
Assignment Requirements
You should create a PyCharm project called A1. In that project, make a new Python file called exactly AnimateShape.py (the .py should be added for you by PyCharm) that draws a fun shape and has it follow the mouse around the screen. You should use the graphics.py module used in Lab 1 (and do use that specific file, I have some small customizations that make it work better for this project) by adding the graphics.py file to the project.
You can read more about that graphics.py module here. Recall that an important skill in programming (and really everywhere) is skimming through documentation to get the idea of how something works and I expect you to develop that skill in this class. For the most part, you should be looking at how to draw different kinds of shapes using that package - in lab we made some circles but other shapes are available.
In your project file, make a function called draw_my_shape with parameters x, y, and win, in that order. This is exactly like the eyes function from Lab 1, but the function is named differently. In this new function, make a fun shape using multiple primitive shapes and different colors. The important part of this function is that if a different x and y is sent to the function, the shape should draw in that new location. The eyes function example from lab did this, so study how that works before starting your own function. The requirements are:
- Use at least three different primitive shapes from graphics.py.
- Use at least three different colors in your project.
- The draw_my_shape function must not query for the mouse position in its code - it should use the x and y that is passed to it when the function is called.
- The drawn shape should be nicely done and interesting. A face with two eyes is not acceptable (since that is just what the lab did). You should show some creativity here.
Then, write a main function that opens a window, sets a background color, and then loops forever. We will review how to define a main function and a loop that repeats forever in class.
Make sure that all the code to start up the window is in the main function and not just random statements in the file. Your code may work, but each part of the code should have a purpose and not be spread around. The autograder system is depending on your code having good style by having everything in a function.
This "open a window and loop" approach is like the code from Lab 1, but put into a (main) function. Inside the loop,
- clear the window
- use the graphics.py function getMousePosition (this is one I added, so it is not in the documentation). The function determines where the mouse cursor is in the window and returns a Point object (see the graphics.py documentation) that corresponds to the location of the cursor. The getMousePosition function does not wait for a click to get the position. Look in the documentation for an example of using the related getMouse function and follow that example to use getMousePosition.
- get the x and y from the Point returned from getMousePosition (refer to Sec 3.1 of the documentation).
- call your draw_my_shape function with the current x and y of the mouse cursor.
- finally, update the screen.
A running program can be stopped from PyCharm or by clicking on the red X close window icon on the window.
At the bottom of the screen, add the code to make the main function be called when the script is run
if __name__ == "__main__": main()
Finally, go through your code and make sure it is well-formatted and any variables you have created have meaningful names.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
