Assignment 27 — coloring within the lines
Due Thursday April 26
Module crayon.py
- Complete the implementation of the functions
flood()
andsweep()
. It uses usa.py to testflood()
andsweep()
- Two other testers for
sweep()
are available
- The two functions should make use of
do.py
to do all coloring. A correct version of do.py will be available after it is due.
Flooding visualization
- Slides exported as PDF
- Slides exported as 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
- Visualization of how
flood()
should work is available above.
- (Highly) 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.
- 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 examples
Warning: fopen(/l/cs1112/public_html/defs/htm/181-trailer): Failed to open stream: No such file or directory in /l/cs1112/public_html/defs/php/read.php on line 5
Unable to open file!