~ubuntu-branches/ubuntu/trusty/pyx/trusty

« back to all changes in this revision

Viewing changes to gallery/misc/julia.py

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2006-11-26 14:04:53 UTC
  • mfrom: (2.1.3 edgy)
  • Revision ID: james.westby@ubuntu.com-20061126140453-1dq3cycpspmlik2t
Tags: 0.9-3
* New maintainer. Thank you for more than three years of
  maintenance,  Graham! Closes: #400087
* Don't hard-code python 2.3 in manual/Makefile.
  Thanks to Matthias Klose for the bug report and patch.
  Closes: #392634
* Remove obsolete dh_python call from debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# contributed by Stefan Schenk
 
2
 
 
3
from cStringIO import StringIO
 
4
from math import sqrt
 
5
from pyx import *
 
6
 
 
7
xiterations = yiterations = 250
 
8
Min_Im = -1.5
 
9
Max_Im = 1.5
 
10
Min_Re = -1.5
 
11
Max_Re = 1.5
 
12
c = 0.41 + 0.3j
 
13
p = color.palette.RedBlue
 
14
 
 
15
def rgbcolortostring(c):
 
16
    return "".join([chr(int(255*c.color[name])) for name in "rgb"])
 
17
 
 
18
data = StringIO()
 
19
 
 
20
# compute fractal
 
21
for y in range(yiterations):
 
22
    for x in range(xiterations):
 
23
        z = complex(1.0*(Max_Re-Min_Re)*x/xiterations + Min_Re,
 
24
                    1.0*(Max_Im-Min_Im)*y/yiterations + Min_Im)
 
25
 
 
26
        for k in range(256):
 
27
            z = z*z + c
 
28
            if abs(z) > 2:
 
29
                # append color(RGB) of the current pixel to the end of data
 
30
                data.write(rgbcolortostring(p.getcolor(1.0/sqrt(k+1))))
 
31
                break
 
32
        else:
 
33
            data.write("\0\0\0")
 
34
 
 
35
# generate image from data
 
36
julia = bitmap.image(xiterations, yiterations, "RGB", data.getvalue())
 
37
juliabitmap = bitmap.bitmap(0, 0, julia, height=10)
 
38
 
 
39
c = canvas.canvas()
 
40
c.insert(juliabitmap)
 
41
c.writeEPSfile("julia")
 
42
c.writePDFfile("julia")