--- fract/mandelzoom.cgi 2001/02/25 22:54:25 1.5 +++ fract/mandelzoom.cgi 2001/06/19 22:27:27 1.9 @@ -1,8 +1,14 @@ #!/usr/bin/python -import cgi, Image, ImageDraw, sys, math +import cgi, Image, ImageDraw, sys, math, signal, errno, os from string import atoi, atof +def handler(signum, frame): + raise os.error, (errno.ETIME, "Timer expired") + +signal.alarm(55) +signal.signal(signal.SIGALRM, handler) + # This is to get backtrace output sys.stderr = sys.stdout @@ -28,12 +34,12 @@ if form.has_key('cx'): cx= atof(form['cx'].value) else: - cx= 0 + cx= 0.0 if form.has_key('cy'): cy= atof(form['cy'].value) else: - cy= 0 + cy= 0.0 if form.has_key('diag'): diag= atof(form['diag'].value) @@ -53,10 +59,10 @@ -Mandel Set Zoomer +Mandelbrot Set Zoomer -

Mandel Set Zoomer

+

Mandelbrot Set Zoomer

@@ -68,12 +74,22 @@ ds="&debug=on" else: ds="" + if form.has_key('image.x') and form.has_key('image.y'): + # Adjust cx and cy + ix= atof(form['image.x'].value) + iy= atof(form['image.y'].value) + owidth= atof(form['owidth'].value) + oheight= atof(form['oheight'].value) + diagp= math.sqrt(owidth**2 + oheight**2) + scale= diagp/diag + cx= (ix/scale) + (cx - (owidth / (scale*2))) + cy= ((oheight-iy)/scale) + (cy - (oheight / (scale*2))) if form.has_key('zoom'): zoom=atof(form['zoom'].value) diag=diag/zoom else: # If no zoom provided, don't actually zoom - zoom= 2 + zoom= 2.0 print 'SRC="mandelzoom.cgi?type=image&width=%s&height=%s&iter=%s%s&diag=%s&cx=%s&cy=%s"' % (str(width), str(height), str(maxiter), ds, str(diag), str(cx), str(cy)), print 'ALIGN=BOTTOM HEIGHT="%s"' % (str(height)), print 'WIDTH="%s">

' % (str(width)) @@ -86,10 +102,7 @@ if zv == 1: print '>Pan' elif zv < 1: - if int(1/zv) == 1/zv: - print '>Out ÷%s' % (str(int(1/zv))) - else: - print '>Out ÷%s' % (str(1/zv)) + print '>Out ÷%s' % (str(1/zv)) else: print '>In ×%s' % (str(zv)) print '' @@ -105,11 +118,14 @@ else: print '>' print '' - for var in (("diag", diag), ("cx", cx), ("cy", cy)): + for var in (("diag", diag), ("cx", cx), ("cy", cy), ("owidth", width), + ("oheight", height)): print '' % var print '' - print """

+ print """

+After changing any settings, don't forget to change the "Zoom" setting +to "Pan" if you don't want to zoom when applying them. """ sys.exit(0) @@ -121,8 +137,8 @@ x= (width/2.0)/scale y= (height/2.0)/scale -c1= cx - x + cy - y * (0+1j) -c2= cx + x + cy + y * (0+1j) +c1= cx - x + (cy - y) * (0+1j) +c2= cx + x + (cy + y) * (0+1j) #print width, height, diag, cx, cy, diagp, scale, x, y, c1, c2 #sys.exit(0) @@ -239,7 +255,13 @@ else: yto= yorig # End at x axis -drawrect((0, yfrom), (xmax, yto)) +try: + drawrect((0, yfrom), (xmax, yto)) +except os.error, the_error: + if the_error[0] != errno.ETIME: + raise os.error, the_error + +signal.alarm(0) print "Content-type: image/png" print