# HP Forums

Full Version: Mandelbrot approximation
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is an approximation which uses the triangle_p function to display the Mandelbrot set. This is much faster about 20 secs) than iterating through all pixels but still fairly slow and the resulting image is blur (a bit like over compressed jpeg). It also consumes a fair amount of memory due to usage of very large matrices. In other words, this is not very nice nor practical, just experimental...

Possible improvements:
- is it possible to somehow use the ITERATE function and achieve faster results?
- would be nice to use cursor and zoom (may be with a box?)
- implement better palette

If anybody can think of possible optimizations, please do not hesitate to share ideas.

Code:
``` grid, color; func(c); export Mandel() begin local cx:=-0.5, cy:=0, zoom:=80, N:=100; local minx,miny,dx,dy; minx:= cx-160/zoom; miny:=cy-119/zoom; dx:=320/N/zoom; dy:=240/N/zoom; // Create the grid grid:=makemat(((I-1)*320/N,(J-1)*240/N),N+1,N+1); color:=makemat(func((minx+I*dx,miny+J*dy)),N+1,N+1); triangle_p(G0,grid,color); wait(0); end; func(c) begin local idxcolor,i:=0, z:=0, max:=50; while i<max do    z:=z^2+c;    if abs(z)>=2 then        idxcolor:=2*pi*i/max;       return RGB(255*(1+sin(idxcolor))/2,0,255*(1+cos(idxcolor))/2);     end;    i:=i+1; end; return RGB(0,0,0); end;```
with FW 6031 (Emulator) this sample Fails with "invalid enty" at the triangle_p function call.
It also fails with an invalid entry in the triangle call in the Android emulator.
Reference URL's
• HP Forums: https://www.hpmuseum.org/forum/index.php
• :