Assignment 29 — coloring within the lines

Due Friday, December 2


Module crayon.py


jpc         jpc

  • Returns a random RGB three-tuple, where each element of the tuple is a random integer value from the interval 0 ... 255.
  • Returns the width of the Image represented by page.
  • Returns the height of the Image represented by page.
  • Returns the coordinate immediately left of spot; that is, its x-coordinate is one less than that of spot and its y-coordinate is the same as that of spot.
  • Returns the coordinate immediately right of spot; that is, its x-coordinate is one greater than that of spot and its y-coordinate is the same as that of spot.
  • Returns the coordinate immediately above spot; that is, its y-coordinate is one less than that of spot and its x-coordinate is the same as that of spot.
  • Returns the coordinate immediately below spot; that is, its y-coordinate is one greater than that of spot and its x-coordinate is the same as that of spot.
  • Returns True or False depending whether coordinate spot is inbounds on the image represented by page.
  • If coordinate spot is inbounds on the image represented by page, the function returns the color at spot in the page; otherwise, the function returns None.
  • Returns True or False depending whether coordinate spot is a colorable pixel in image page. To be colorable spot must be inbounds and equal to the background color bg.
  • If spot is a colorable pixel on image page, then that pixel is set to c; otherwise, no action is taken.

Flooding visualization


Function flood( page, spot, c, bg )

 If the spot on the page is not colorable

  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( spot, bg )

page_width = do.get_width( page )

page_height = do.get_height( page )

for px in range( 0, page_width ) :

  for py in range( 0, page_height ) :

  spot = (px, py) # spot is the current drawing coordinate of

  # interest.

  # if the pixel at spot is colorable, generate a random color

  # and start a flood from there

  pass



Coloring examples


usa         usa


uva logo         uva logo


trex         trex


mandala         mandala


flower         flower


girl and dog         girl and dog