/[cvs]/fract/mandelzoom.cgi
ViewVC logotype

Diff of /fract/mandelzoom.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by teddy, Sat Feb 24 21:36:47 2001 UTC revision 1.2 by teddy, Sun Feb 25 05:49:07 2001 UTC
# Line 1  Line 1 
1  #!/usr/bin/python  #!/usr/bin/python
2    
3  import cgi, Image, ImageDraw, sys  import cgi, Image, ImageDraw, sys, math
4  from string import atoi  from string import atoi, atof
5    
6    sys.stderr = sys.stdout
7    
8  form= cgi.FieldStorage()  form= cgi.FieldStorage()
9    
10  # Image size  # Image size
11  if form.has_key('width'):  if form.has_key('width'):
12      width=atoi(form['width'].value)      width= atoi(form['width'].value)
13  else:  else:
14      width= 570      width= 570
15  if form.has_key('height'):  if form.has_key('height'):
16      height=atoi(form['height'].value)      height= atoi(form['height'].value)
17  else:  else:
18      height= 570      height= 570
19    
20  xmax, ymax = width-1, height-1          # Coordinate maximums  xmax, ymax = width-1, height-1          # Coordinate maximums
21    
22    # Complex number in center of image is (cx+cy*j)
23    if form.has_key('cx'):
24        cx= atof(form['cx'].value)
25    else:
26        cx= 0
27    
28    if form.has_key('cy'):
29        cy= atof(form['cy'].value)
30    else:
31        cy= 0
32    
33    if form.has_key('diag'):
34        diag= atof(form['diag'].value)
35    else:
36        diag= math.sqrt(8)
37    
38  debug= form.has_key('debug')  debug= form.has_key('debug')
 if debug:  
     del form['debug']  
39    
40  if form.has_key('iter'):  if form.has_key('iter'):
41      maxiter=atoi(form['iter'].value)      maxiter= atoi(form['iter'].value)
     del form['iter']  
42  else:  else:
43      maxiter= 270      maxiter= 270
44    
45  sys.stderr = sys.stdout  #print "Content-Type: text/plain"
46  print "Content-Type: text/plain"  #print ""
 print ""  
47    
48  # If type==html, then output an HTML page, not an image  # If type!=image, then output an HTML page, not an image
49  if form.has_key('type') and form['type'].value == "html":  if not (form.has_key('type') and form['type'].value == "image"):
     del form['type']  
50      print """Content-Type: text/html      print """Content-Type: text/html
51    
52  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
# Line 45  if form.has_key('type') and form['type'] Line 58  if form.has_key('type') and form['type']
58    
59  <FORM ACTION="mandelzoom.cgi" METHOD=GET>  <FORM ACTION="mandelzoom.cgi" METHOD=GET>
60    
61  <!-- implies TYPE=SUBMIT -->  <!-- implies TYPE=SUBMIT -->"""
62      <INPUT TYPE=IMAGE NAME="image" SRC="mandelzoom.cgi?%s" ALIGN=BOTTOM      print '<INPUT TYPE=IMAGE NAME="image"',
63      HEIGHT="%s" WIDTH="%s">      print 'WIDTH="%s"' % (str(width)),
64        print 'HEIGHT="%s"' % (str(height)),
65        if debug:
66            ds="&debug=on"
67        else:
68            ds=""
69        if form.has_key('zoom'):
70            zoom=atoi(form['zoom'].value)
71            diag=diag/zoom
72        else:
73            # If no zoom provided, don't actually zoom
74            zoom= 2
75        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)),
76        print 'ALIGN=BOTTOM HEIGHT="%s"' % (str(height)),
77        print 'WIDTH="%s"><P>' % (str(width))
78        print 'Zoom: <SELECT NAME="zoom">'
79        for zv in [-5, -3, -2, 1, 2, 3, 5]:
80            print '<OPTION',
81            if zv==zoom:
82                print 'SELECTED',
83            print 'VALUE="%s"' % (str(zv))
84            if zv < 0:
85                print '>÷%s' % (str(-zv))
86            else:
87                print '>×%s' % (str(zv))
88        print '</SELECT>'
89        print """Width: <INPUT TYPE=TEXT NAME="width" MAXLENGTH="4" SIZE="3"
90        VALUE="%s">
91        Height: <INPUT TYPE=TEXT NAME="height" MAXLENGTH="4" SIZE="3"
92        VALUE="%s">
93      Iterations: <INPUT TYPE=TEXT NAME="iter" MAXLENGTH="4" SIZE="3"      Iterations: <INPUT TYPE=TEXT NAME="iter" MAXLENGTH="4" SIZE="3"
94      VALUE="%s">      VALUE="%s">
95      Debug mode: <INPUT TYPE=CHECKBOX NAME="debug" %s>"""      Debug mode: <INPUT TYPE=CHECKBOX NAME="debug" """ % (str(width), str(height), str(maxiter))
96        if debug:
97            print 'CHECKED>'
98        else:
99            print '>'
100      for key in form.keys():      for key in form.keys():
101          print '<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">' % (key, form[key].value)          if key not in ["zoom", "type", "debug", "image.x", "image.y", "iter", "height", "width"]:
102                print '<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">' % (key, form[key].value)
103        print '<INPUT TYPE=HIDDEN NAME=type VALUE="html">'
104    
105      print """</FORM>      print """</FORM>
106  </BODY></HTML>"""  </BODY></HTML>"""

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26