Class 40 — November 29
Color within the lines
Look both ways
Agenda
- Create library to paint coloring book pages by implementating HW 28 module
crayon
functionsflood()
andsweep()
.
Selfie
Redownload one more time
Download
Downloads to test function flood()
Downloads to test function sweep()
Flooding visualization
- Discussion (PDF)
- Discussion (MP4)
Function flood( drawing, spot, c, bg=(255,255,255) )
- If
spot
is not a colorable pixel ondrawing
, then no action is taken.
- If instead
spot
is a colorable pixel ondrawing
, then all pixel locactions reachable fromspot
traversing only colorable pixels are set to colorc
.
- The function does not return a value.
- Recommended algorithm
If the spot on the drawing is not empty
return
Color the spot using c
Create a to-do list with spot as its element
While the to-do list is not empty
Pop an element from the to-do list and assign it to v
If v’s left is empty, paint it and add to to-do list
If v’s right is empty, paint it and add to to-do list
If v’s above is empty, paint it and add to to-do list
If v’s below is empty, paint it and add to to-do list
Function sweep( drawing, bg=(255,255,255) )
- For every
bg
colorabledrawing
pixel, aflood()
is performed. For each flooding a new random color is used.
- The function does not return a value.
- Note, my implementation considers the rows of pixels making up a picture from top to bottom. Within a row, the pixels were considered left to right. If you do a different order, your picture could look different. Also, my implementation only generates a random color only if the pixel under consideration is colorable.
Coloring by va.py
Coloring by usa.py
Coloring by uva.py
Coloring by book.py
Coloring by street-art.py