def test_make_new_color(): """Test picture module functions create_color to ensure it creates Color objects identical to ones created manually.""" color_arrays = [[1, 1, 1], [0, 64, 255], [255, 255, 255], [34, 78, 12]] for color_array in color_arrays: # create using all three ways color_make = media.create_color(color_array[0], color_array[1], color_array[2]) color_manual = Color(color_array[0], color_array[1], color_array[2]) assert color_make == color_manual, \ 'Colors not the same (' + str(color_manual) + ')'
def overlay_color(pix1, pix2): '''(Pix1, Pix2) -> Color Return a new color made up of 80% of the color values of the first pixel and 20% of the color values of the second pixel.''' r1 = int(media.get_red(pix1)) r2 = int(media.get_red(pix2)) g1 = int(media.get_green(pix1)) g2 = int(media.get_green(pix2)) b1 = int(media.get_blue(pix1)) b2 = int(media.get_blue(pix2)) red = (r1 * 0.8) + (r2 * 0.2) green = (g1 * 0.8) + (g2 * 0.2) blue = (b1 * 0.8) + (b2 * 0.2) return media.create_color(red, green, blue)
def overlay_picture(pic, pic2): '''(Pic, Pic2) -> Picture Return a new picture with each pixel's color values made up of 80% of the color values of the corresponding pixel in the first picture and 20% of the color values of the corresponding pixel in the second picture''' new_pic = media.copy(pic) for pix in new_pic: x = media.get_x(pix) y = media.get_y(pix) p1 = media.get_pixel(pic, x, y) p2 = media.get_pixel(pic2, x, y) red = (int(p1.get_red()) * 0.8) + (int(p2.get_red()) * 0.2) green = (int(p1.get_green()) * 0.8) + (int(p2.get_green()) * 0.2) blue = (int(p1.get_blue()) * 0.8) + (int(p2.get_blue()) * 0.2) new_color = media.create_color(red, green, blue) media.set_color(pix, new_color) return new_pic
def overlay_picture(pic, pic2): '''(Pic, Pic2) -> Picture Return a new picture with each pixel's color values made up of 80% of the color values of the corresponding pixel in the first picture and 20% of the color values of the corresponding pixel in the second picture''' new_pic=media.copy(pic) for pix in new_pic: x = media.get_x(pix) y = media.get_y(pix) p1 = media.get_pixel(pic, x,y) p2 = media.get_pixel(pic2,x,y) red = (int(p1.get_red()) * 0.8) + (int(p2.get_red()) * 0.2) green = (int(p1.get_green()) * 0.8) + (int(p2.get_green()) * 0.2) blue = (int(p1.get_blue()) * 0.8) + (int(p2.get_blue()) * 0.2) new_color = media.create_color(red, green, blue) media.set_color(pix, new_color) return new_pic
import media import color pic = media.create_picture(100, 200, media.black) for i in range(media.get_width(pic)): for j in range(media.get_height(pic)): pixel = media.get_pixel(pic, i, j) media.set_color(pixel, media.create_color(i % 255, j % 255, 0)) pic.show()
pix2 = media.get_pixel(pic, 1, 1) media.set_color(pix1, media.orange) media.set_color(pix2, media.blue) result = a1.overlay_color(pix1, pix2) assert isinstance(result, media.Color), \ '''a1.overlay_color(pix1, pix2) should return a Color, but it returned %s.''' % (type(result)) # Type check a1.overlay_picture pic1 = media.create_picture(2, 3) pix1 = media.get_pixel(pic, 0, 0) pix2 = media.get_pixel(pic, 1, 1) r1, g1, b1 = 50, 100, 200 r2, g2, b2 = 40, 150, 0 media.set_color(pix1, media.create_color(r1, g1, b1)) media.set_color(pix2, media.create_color(r2, g2, b2)) pic2 = media.create_picture(2, 3) result = a1.overlay_picture(pic1, pic2) assert isinstance(result, media.Picture), \ '''a1.overlay_picture(pic1, pic2) should return a Picture, but it returned %s.''' % (type(result)) # Type check a1.flip pic = media.create_picture(2, 4) result = a1.flip(pic) assert isinstance(result, media.Picture), \ '''a1.flip(pic) should return a Picture, but it returned