CS 115 Lab 3, Part B: Draw arbitrary circles
[Back to lab instructions]
The Big Picture
For this part of the lab, you will use the graphics package to initially draw a bunch of circles.
Later in the lab, we will use loops to automatically generate multiple circles.
Instructions
- In IDLE, go to the File menu and select "New File." Copy-paste the following program into the new window, substituting your name for the italicized text:
"""
Program: CS 115 Lab 3b
Author: Your name
Description: Using the graphics package, this program will draw a circle.
"""
from graphics import *
def main():
window = GraphWin("Circles", 800, 800)
center = Point(100, 200) # create a point to serve as the center of the circle
radius = 40
circle = Circle(center, radius) # create a circle centered at "center" with radius "radius"
circle.setOutline('blue')
circle.draw(window) # draw the circle in the window that we created earlier
window.getMouse() # wait for the mouse to be clicked in the window
window.close() # close the window after the mouse is clicked in the window
main()
- Save this program as lab03b.py.
- Run the program.
You should see a circle with a blue outline and a radius of 40 pixels, centered at the point (100, 200). If you run into any trouble with the graphics package, please call a lab instructor.
- If necessary, review the description of this code in the pre-lab.
- Once you are comfortable with these concepts, add a few more circles to this program. Give them different radii and colors, and place them in different points in the window. Pay particular attention to how the coordinates of the center affect the placement of the circles. This page has a list of colors you can use.
- Once you have drawn at least 5 circles, continue to Part C.