WEEK05: computer graphics, using objects
---------------------------------------------------------------
W: colors
QUIZ 2 today!
REVIEW random stars from last time:
width = 500
height = 400
nstars = 700
win = GraphWin("stars", width, height)
win.setBackground("black")
# stars
for i in range(nstars):
x = randrange(0,width)
y = randrange(0,height)
star = Point(x,y)
star.setFill("white")
star.draw(win)
COLOR...rgb = red green blue:
- try using the color_rgb function!
- each color component (r, g, b) can have a value from 0 to 255
(0 means none/dark, 255 means full on/bright)
>>> from graphics import *
>>> w = GraphWin()
>>> p = Point(50,70)
>>> c = Circle(p,30)
>>> c.draw(w)
>>> color = color_rgb(0,0,0) # black
>>> c.setFill(color)
>>> color = color_rgb(0,0,255) # blue
>>> c.setFill(color)
>>> color = color_rgb(0,255,0) # green
>>> c.setFill(color)
>>> color = color_rgb(0,255,145) # greenish-blue
>>> c.setFill(color)
YOUR TURN: add some color to the random stars program!