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

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

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26