# create a grayscale pgm image file width = 200 height = 150 maxIntensity = width + height # pixels are scaled 0 to maxIntensity f = open("myfile.pgm", "w") # built-in function to open a text file f.write("P2\n") # write the pgm file magic number f.write(str(width) + " " + str(height) + "\n") # write width and height f.write(str(maxIntensity) + "\n") # write value of brightest pixel for row in range(height): # row 0 will be displayed at the top for col in range(width): # replace next line with your own code to make an image f.write(str(row + col) + " ") # lower right will be brightest f.write("\n") f.close() # to display your image: # # python pgm.py # File --> Open # # or # # python pgmdisplay.py myfile.pgm