Questions about anything so far?
I've looked over the homework submitted - looks good.
Homework for Tuesday is posted.
## Incorrect way to create two circles.
leftEye = Circle (Point (80 , 50) , 5)
leftEye.setFill('yellow')
leftEye.setOutline('red')
rightEye = leftEye # OOPS
rightEye.move (20, 0)
## works but has a "code smell" (google it) : "duplicated code"
leftEye = Circle (Point (80 , 50) , 5)
leftEye.setFill('yellow')
leftEye.setOutline('red')
rightEye = Circle (Point (100 , 50) , 5)
rightEye.setFill('yellow')
rightEye.setOutline('red')
# A better way.
leftEye = Circle (Point (80 , 50) , 5)
leftEye.setFill('yellow')
leftEye.setOutline('red')
rightEye = leftEye.clone() # make a copy with same position, color, etc.
rightEye.move(20, 0)
Show code & discuss the several versions in the chapter.
#
# color grid | Jim M | python class demo | Sep 2018
#
from graphics import *
color_min = 0
color_max = 255
pixels_per_color = 3
window_size = (color_max - color_min + 1) * pixels_per_color
window_title = "colors!"
window = GraphWin(window_title, window_size, window_size)
blue = 100
for red in range(color_min, color_max+1):
for green in range(color_min, color_max+1):
left = red * pixels_per_color
right = left + pixels_per_color
top = green * pixels_per_color
bottom = top + pixels_per_color
color = color_rgb(red, green, blue)
box = Rectangle(Point(left, top), Point(right, bottom))
# box.setOutline(color) # if not set, outline will be black
box.setFill(color)
box.draw(window)
done = input("Done?")
Other things to try :
... ideas ?