--- fract/julia3.cgi 2001/02/24 15:57:15 1.1.1.1 +++ fract/julia3.cgi 2001/02/25 22:54:15 1.3 @@ -1,11 +1,28 @@ #!/usr/bin/python -import cgi, Image, ImageDraw, sys +import sys + +sys.stderr = sys.stdout +#print "Content-Type: text/plain" +#print + +import cgi, Image, ImageDraw from string import atoi +from Drawrect import drawrect + form= cgi.FieldStorage() -width, height= 570, 570 # Image size +# Image size +if form.has_key('width'): + width=atoi(form['width'].value) +else: + width= 570 +if form.has_key('height'): + height=atoi(form['height'].value) +else: + height= 570 + xmax, ymax = width-1, height-1 # Coordinate maximums inx=max(0, min(atoi(form['image.x'].value), xmax)) @@ -33,51 +50,6 @@ julia= Image.new("L", (width, height)) draw= ImageDraw.Draw(julia) -def drawrect((x1, y1), (x2, y2)): - color= plot(x1, y1) - cut= 0 - x, y= x1+1, y1 - while x<=x2: - if color<>plot(x, y): - cut= 1 - x= x+1 - x, y= x2, y1+1 - while y<=y2: - if color<>plot(x, y): - cut= 1 - y= y+1 - x, y= x2-1, y2 - while x>=x1: - if color<>plot(x, y): - cut= 1 - x= x-1 - x, y= x1, y2-1 - while y>y1: - if color<>plot(x, y): - cut= 1 - y= y-1 - if x2-x1<=1 or y2-y1<=1: - return - if cut: - if x2-x1 > y2-y1: # If wider than high - xc= ((x2-x1)/2)+x1 - drawrect((x1, y1), (xc, y2)) - drawrect((xc, y1), (x2, y2)) - else: # if higher than wide - yc= ((y2-y1)/2)+y1 - drawrect((x1, y1), (x2, yc)) - drawrect((x1, yc), (x2, y2)) - else: - if not debug: - draw.rectangle([x1, y1, x2, y2], fill= color) - if yorig >= 0: # The x axis is visible on image - # mirror over yorig, but keep within image - y1m= max(0, min(2*yorig-y1, ymax)) - y2m= max(0, min(2*yorig-y2, ymax)) - x1m= max(0, min(2*xorig-x1, xmax)) - x2m= max(0, min(2*xorig-x2, xmax)) - draw.rectangle([x1m, y1m, x2m, y2m], fill= color) - def plot(x, y): z= constant(x, y) i= 0 @@ -106,12 +78,26 @@ raise IndexError, the_error return color + + # Initial default values yfrom= 0 yto= ymax yorig= -1 # The pixel coordinate of the x axis; negative means not on image xorig= -1 + +def fillrect(x1, y1, x2, y2, color): + draw.rectangle([x1, y1, x2, y2], fill= color) + if yorig >= 0: # The x axis is visible on image + # mirror over yorig, but keep within image + y1m= max(0, min(2*yorig-y1, ymax)) + y2m= max(0, min(2*yorig-y2, ymax)) + x1m= max(0, min(2*xorig-x1, xmax)) + x2m= max(0, min(2*xorig-x2, xmax)) + draw.rectangle([x1m, y1m, x2m, y2m], fill= color) + + # Check if we should do mirroring if c1.imag > 0 and c2.imag < 0: # the x axis is visible yorig= int((-c1.imag/(c2.imag-c1.imag))*height) # pixel pos. of x axis @@ -123,8 +109,14 @@ if c1.real < 0 and c2.real > 0: xorig= int((-c1.real/(c2.real-c1.real))*height) -drawrect((0, yfrom), (xmax, yto)) +if not debug: + funcpoint= fillrect +else: + funcpoint= lambda x1, y1, x2, y2, color: x1+y1+x2+y2+color + +drawrect((0, yfrom), (xmax, yto), plot, funcpoint) print "Content-type: image/png" print julia.save(sys.stdout, "PNG") +