From the class Code as a Liberal Art · Spring 2022
part2/unit1_hw3_part2.py
import sys
import random
from PIL import Image
if len(sys.argv) != 2:
exit("This program requires one argument: the name of the image file that will be created.")
# Make a new 400x400 image
img = Image.new("RGB", (400,400) )
for y in range(400):
for x in range(400):
r = 0
g = 0
b = 0
if x % 50 > 25:
r = random.randrange(0, 255)
if y % 50 > 25:
b = random.randrange(0, 255)
if x % 100 > 50 and y % 100 > 50:
g = random.randrange(0, 255)
pixel = (r, g, b)
img.putpixel( (x,y), pixel )
img.save(sys.argv[1])