Become familiar with the graphics library
1. Draw a Circle
#! /usr/bin/python3
# ===================================================================
# print a circle at the center of the window
# ===================================================================
import graphics as gr
win_height = 801
win_width = 801
# ---- create a window
win = gr.GraphWin("Draw Circle", win_width, win_height)
win.setBackground("white")
# ---- draw a circle
c = gr.Circle(gr.Point(win_width/2,win_height/2), 100)
c.draw(win)
# ---- end program
win.getMouse() # wait for click in windows
win.close() # close window
1.2. Fill in Circle
- make the fill color to "red"
- make the the outline 1 pixel
- change the fill color to rgb(255,255,255)
- change the width
- change the size
- what colors are available?
1.3. Draw a line
- make the fill color to "green"
- make the the outline 1 pixel
- draw a square
- change the fill color
- change the width
- change the size
Draw a spiral
1.4. Draw a rectangle
- make the fill color to "blue"
- make the the outline 1 pixel
- draw a square
- change the fill color
- change the width
- change the size
1.5. Draw an oval
- make the fill color to "yellow"
- make the the outline 1 pixel
- change the fill color (try gray?)
- change the width
- change the size
1.6. Draw an polygon
- make the fill color to "black"
- make the the outline 1 pixel
- change the fill color
- change the width
- change the size
1.7. Mouse Input
1.7.1. When the mouse is clicked in the window, draw a circle at that location.
Erase the circle at the old location, if any.
1.8. Key Input
1.8.1. Draw a circle or other graphics object in the window. Use the arrow keys to
move it around in the window. Use the "q" or "Q" key to exit the program.
1.9. Draw text
- make the fill color to "red"
- can you make the the outline 1 pixel
- can you change the fill color
- can you change the width
- can you change the size
- what fonts are available?
- change the font
- draw multi-line text
in 1.7.1. and/or 1.8.1. display the coordinates of the mouse click
in the window.