[Numpy-discussion] The NumPy Mandelbrot code 16x slower than Fortran
Robert Cimrman
cimrman3@ntc.zcu...
Mon Jan 23 07:02:54 CST 2012
On 01/23/12 13:51, Sturla Molden wrote:
> Den 23.01.2012 13:09, skrev Sebastian Haase:
>>
>> I would think that interactive zooming would be quite nice
>> ("illuminating") .... and for that 13 secs would not be tolerable....
>> Well... it's not at the top of my priority list ... ;-)
>>
>
> Sure, that comes under the 'fast enough' issue. But even Fortran might
> be too slow here?
>
> For zooming Mandelbrot I'd use PyOpenGL and a GLSL fragment shader
> (which would be a text string in Python):
>
> madelbrot_fragment_shader = """
>
> uniform sampler1D tex;
> uniform vec2 center;
> uniform float scale;
> uniform int iter;
> void main() {
> vec2 z, c;
> c.x = 1.3333 * (gl_TexCoord[0].x - 0.5) * scale - center.x;
> c.y = (gl_TexCoord[0].y - 0.5) * scale - center.y;
> int i;
> z = c;
> for(i=0; i<iter; i++) {
> float x = (z.x * z.x - z.y * z.y) + c.x;
> float y = (z.y * z.x + z.x * z.y) + c.y;
> if((x * x + y * y)> 4.0) break;
> z.x = x;
> z.y = y;
> }
> gl_FragColor = texture1D(tex, (i == iter ? 0.0 : float(i)) / 100.0);
> }
>
> """
>
> The rest is just boiler-plate OpenGL...
>
> Sources:
>
> http://nuclear.mutantstargoat.com/articles/sdr_fract/
>
> http://pyopengl.sourceforge.net/context/tutorials/shader_1.xhtml
Off-topic comment: Or use some algorithmic cleverness, see [1]. I recall Xaos
had interactive, extremely fast a fluid fractal zooming more than 10 (or 15?)
years ago (-> on a laughable hardware by today's standards).
r.
[1] http://wmi.math.u-szeged.hu/xaos/doku.php
More information about the NumPy-Discussion
mailing list