Question: Jill is developing an image processing program that creates artworks with random colors. The inputs to the program are the width and height of a
Jill is developing an image processing program that creates artworks with random colors. The inputs to the program are the width and height of a new image, and the name of a file to which the image should be saved. Here is the code for Jills program:
from images import Image
import random
def main:
Generates and saves images with random colors.
Inputs: The image's width, height,
and output file name."""
width intinputEnter the image's width:
height intinputEnter the image's height:
fileName inputEnter the image's file name:
# Create a table of unique colors for GIF image
colors
while lencolors:
r random.randint
g random.randint
b random.randint
if not r g b in colors:
colors.appendr g b
image Imagewidth height
for y in rangeimagegetHeight:
for x in rangeimagegetWidth:
color random.choicecolors
image.setPixelx y color
printClose the image window to quit.
image.draw
image.savefileName
if namemain:
main
When Jill runs the program, she enters her inputs and views the image before its saved. But when she closes the window and the program attempts to save the image, Python raises an error that the image has too many colors, as shown in Figure
Python program that creates and saves artwork with random colors. In the IDLE shell window, the random art dot p y program executes. The following prompts are displayed. Enter the image
Figure
Determine why this error occurs and correct it Jack reminds Jill that the GIF format supports at most unique colors.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
