#!/usr/bin/env python from os import system h=256 w=256 pfile=open('colors.ppm','w') blue=int(raw_input("Enter blue value between 0 and 255==>")) print "You entered blue=",blue print "Now making image" #print header pfile.write("P3\n") #use P3 for ascii, P6 for binary pfile.write("%d %d\n" % (w, h)) pfile.write("255\n") #print raster for j in range(0,w): #in python, the range stops at w-1 for i in range(0,h): red=i green=j pfile.write("%d %d %d\n" % (red,green,blue)) #use with P3 # pfile.write("%c%c%c" % (red,green,blue))#use with P6 pfile.close() print "file colors.ppm was written" #display the image print "now trying to display image to your monitor (please wait)" system("display colors.ppm") #the import statement at top was needed for this