#
# create rainbow 1D texture.
# code based on 'Simulation diffraction' chapter in GPU Gems
#

import PIL, Image, math

c     = 4.0
width = 128

def	bump ( x ):
	if abs ( x ) > 1:
		return 0
		
	return 1.0 - x*x
	
def	color ( y ):
	red   = int ( 255 * bump ( c * ( y - 0.75 ) ) + 0.5 )
	green = int ( 255 * bump ( c * ( y - 0.5  ) ) + 0.5 )
	blue  = int ( 255 * bump ( c * ( y - 0.25 ) ) + 0.5 )
	
	return ( red, green, blue )
	
im = Image.new ( "RGB", (width, 1 ) )

for x in range ( width ):
	y   = float ( x ) / float ( width )
	clr = color ( y )
	im.putpixel ( (x, 0), clr )
	
im.show ()
im.save ( "rainbow.bmp", "bmp" )
