Release Mandelbrot Lazarus sample


Farox

Certified Guru
Joined
Jan 8, 2009
Messages
2,430
Age
56
Location
Italy
Website
rbnet.it
Hi

i was playing with Lazarus and FPC and i found an interesting Mandelbrot program made in FreePascal +Lazarus.

It's from http://corpsman.de/index.php?doc=beispiele/mandelbrot

 this guy have a site (in german only :( ) full of beautyfull examples and nice games (not all are open source...as i understand) ..pay him a visit if interested.

Now i started recompiling for pandora this good and fast Mandelbrot program, and have adapted the GUI for Pandora resolution and adjusted widht and height of saved images.

Download from the repo

07 Nov 2015. release 0.0.1.2:

With this release the original author have done a good job and implemented in the code a function that made it possible to correctly load and save .mdl files from the 2 arch (x86 and ARM), so now you can start explore mandelbrot fractals on your x86 PC and continue exploring it on your Pandora and vice versa.

Added the original .mdl files published by the author, so you have some ready file to begin exploring.

Updated also the sources on pnd.

some shots:

Wsydrhj.png


xnT8PlE.png


uhQ9GIg.png


Have fun with it.
 
Last edited by a moderator:
I'm not into fractals, but it should make a nice pnd. The interface and the renderings look nice.
 
Ok i maybe try to build a pnd....but i just discovered a nasty bug in saving/loading the Mandelbrot that i need to investigate.
 
I have investigated and there's not a problem with logic of the program...but a problem of type conversion.

The problem occur when you want to load an mdl (stand for mandelbrot) file into the program. The mdl file is only a bunch of byte representing the coordinate and various option to recreate the mandelbrot. If you load the mdl file created with the x86 version of the program it wont work it say division by zero, if you load the mdl file created on Pandora no problem it works.

Now in the code the author use Extended type for the numbers, where Extended on a x86 is 20 digit number on Arm is only 16 digit (as Extended is considered as Double).

So how i can resolve this....i need a proper programmer, the source is present on the zipped package on the first post.

Please help.
 
I'm not familiar with pascal, so I can't say what's the most feasible approach.  You could try defining a 20-bit integer type and using that in all places where an Extended is used.  I don't know why x86 processors use that odd size of two bytes and a nybble, but under ARM it should just be a matter of doing the maths in 32-bit precision, then masking the most significant 12 bits, so should still run pretty well.

If it's not possible in Pascal to define types like you can in C, then you might need to load the numbers into a series of bytes and then shuffle the bits into the appropriate 16-bit doubles, discarding the least signficant 4 bits.  I'm not sure if this loss of precision would affect the program though - have you tested zooming into the image on Pandora and PC, are there any differences which would be problematic?

Also, perhaps Pascal handles this already, but you might want to be aware that x86 is a big-endian processor, while ARM is little-endian.  In other words, in a 16-bit (2-byte) number the most significant byte will be written first on x86, while the least significant one will be written first on ARM.  I'm not sure how this extends to 20-bit numbers to be honest.
 
I think he is talking about the 80 bit (or something) float format the X86 FPU is using.
 
Last edited by a moderator:
I had exactly this problem with PandaBAS - all values in that are floats, and the Pandora only uses doubles where the x86 uses extended format. This meant that loading any binary with floats stored inside on the Pandora would fail.

I haven't gotten around it - accuracy of math operations on the x86 is nice but the Pandora's version suffers due to the use of doubles and there's nothing I can do about that.

D.
 
Ah, I wondered if float were involved, as fixed point fractal algorithms are hard work, and thus pretty rare.  Yeah, that makes sense - extended double-precision numbers on x86 (up to 80-bit) while ARM only supports conventional double-precision (64 bit).  You can ignore most if not all of my last post if that's the case.

I've not investigated the code to find where it loads and saves files, and don't really understand pascal or floating point numbers anyway.  I don't think I can help here, sorry.
 
Yes i was referring to FPU types as described here http://www.freepascal.org/docs-html/ref/refsu6.html

I haven't gotten around it - accuracy of math operations on the x86 is nice but the Pandora's version suffers due to the use of doubles and there's nothing I can do about that.
Thank's I was searching on the web and have found only people that saying the same...so now i know that's a conversion is not possible.

Maybe i could package in pnd the program without the examples so no loading problems with the x86 one's.
 
One thing you could do is to modify the saving routine to save explicitly using double precision. Then run the examples on your x86 box, and save them out overwriting the old ones. That way the Pandora will be able to read them. You might need to make sure that what you get on the pandora is roughly the same as the x86 examples though, and either tweak them or leave them out altogether...

A bit of work, but not much more than an hour or so.

D.
 
One thing you could do is to modify the saving routine to save explicitly using double precision. Then run the examples on your x86 box, and save them out overwriting the old ones. That way the Pandora will be able to read them. You might need to make sure that what you get on the pandora is roughly the same as the x86 examples though, and either tweak them or leave them out altogether... A bit of work, but not much more than an hour or so.
Thank for suggestion but my skills are not enough for this task...i have decided that i will package up a pnd without the .mdl examples.

But now i have a problem....What's wrong with this PXML file ?

<?xml version="1.0" encoding="UTF-8"?>
<PXML xmlns="http://openpandora.org/namespaces/PXML" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="PXML_schema.xsd">
<!-- please see http://pandorawiki.org/PXML_specification for more information before editing, and remember the order does matter -->

<package id="mandelfpc-28656">

<author name="Farox" website="http://farox.rbnet.it/"/>
<version major="0" minor="0" release="1" build="1"/> <!--This programs version-->

<titles>
<title lang="en_US">Mandelbrot Sample</title>
</titles>
<descriptions>
<description lang="en_US">A Mandelbrot explorer created with FreePascal and Lazarus.
Features supported: Fast drawing, explore Mandelbrot and associated Julia set, Zoom, Save image in BMP format,
Load external color gradient and included a standalone Gradient editor to create more.
Gui adapted for Pandora screen, Sources included in PND.</description>
</descriptions>
</package>


<application id="mandelbrot-28656" appdata="mandelfpc">
<exec command="scripts/mandelbrot.sh"/>
<titles>
<title lang="en_US">Mandelbrot Sample</title>
</titles>

<author name="Corpsman" website="http://corpsman.de/index.php?doc=beispiele/mandelbrot"/>
<version major="0" minor="0" release="1" build="1"/> <!--This programs version-->
<osversion major="1" minor="0" release="0" build="0"/> <!--The minimum OS version required-->

<description lang="en_US">A Mandelbrot explorer created with FreePascal and Lazarus.</description>

<icon src="./icon.png"/>

<previewpics>
<pic src="previews/shot1.png"/>
<pic src="previews/shot2.png"/>
<pic src="previews/shot3.png"/>
<pic src="previews/shot4.png"/>
<pic src="previews/shot5.png"/>
<pic src="previews/shot6.png"/>
<pic src="previews/shot7.png"/>
<pic src="previews/shot_ed.png"/>
</previewpics>

<licenses>
<license name="None" url="" sourcecodeurl=""/>
</licenses>
<!--<info name="mandelbrot documentation" type="text/plain" src="/mnt/utmp/mandelfpc/readme.txt"/>-->

<categories>
<!-- http://standards.freedesktop.org/menu-spec/latest/apa.html -->
<category name="Graphics">
<subcategory name="2DGraphics"/>
</category>
</categories>

<!--
<associations>
<association name="Deinterlaced Bitmap Image" filetype="image/bmp" exec="-f %s"/>
<association name="Style sheet system crasher" filetype="text/css" exec="-f %s"/>
</associations>
-->
<!--<clockspeed frequency="600"/>-->
</application>


<application id="gradienteditor-28656" appdata="mandelfpc">
<exec command="scripts/gradient-editor.sh"/>
<title lang="en_US">Gradient Editor</title>

<author name="Corpsman" website="http://corpsman.de/index.php?doc=beispiele/mandelbrot"/>
<version major="0" minor="0" release="1" build="1"/> <!--This programs version-->
<osversion major="1" minor="0" release="0" build="0"/> <!--The minimum OS version required-->

<description lang="en_US">A Gradient Editor to create some new cool gradient color.</description>

<icon src="./icon.png"/>

<licenses>
<license name="None" url="" sourcecodeurl=""/>
</licenses>
<!--<info name="gradient-editor documentation" type="text/plain" src="/mnt/utmp/mandelfpc/readme.txt"/>-->

<categories>
<!-- http://standards.freedesktop.org/menu-spec/latest/apa.html -->
<category name="Graphics">
<subcategory name="2DGraphics"/>
</category>
</categories>

<!--
<associations>
<association name="Deinterlaced Bitmap Image" filetype="image/bmp" exec="-f %s"/>
<association name="Style sheet system crasher" filetype="text/css" exec="-f %s"/>
</associations>
-->
<!--<clockspeed frequency="600"/>-->
</application>


</PXML>
I have built the pnd and it work but i have 2+2 menu entry like in this shot:

nEAGXkt.png


The entrys with the icon works (if clicked first and not trying to run the other 2 without the icon), but the other 2 didn't work and if i try to run before the other 2 make impossible to run the pnd.

Anybody please help...this is my first pnd with two programs.
 
Last edited by a moderator:
So you fixed the 80bits double -> 64bits double issue?

I think yes..anyway not my work really...but the original author with some help from german lazarus forum.

Here is the code extracted from Unit1.pas

// Quelle:  http://www.lazarusforum.de/viewtopic.php?f=9&t=9148
Procedure Write10ByteExtended(val: extended; Const Stream: TStream);
// Soll eine 8-byte Extended abspeichern, als sei sie 10-Byte Groß
Var
  OutData: Array[0..9] Of byte;
  tmpdbl : double;
  tmpBArr : Array[0..7] of byte absolute tmpdbl;
  tmpWArr : Array[0..3] of Word absolute tmpdbl;
  tmpInt64 : Int64 absolute tmpdbl;
  Exponent,
  VZ     : Word;
Begin
  tmpdbl := val;
  Vz :=  Ord(tmpdbl<0) *32768;
  //Exponent formen
  Exponent := tmpWArr[3]-Vz;
  Exponent := (Exponent shl 1) shr 5 +(-1023+16383) + Vz;
  //Mantisse schieben und oberstes Bit setzen
  tmpInt64 := (tmpInt64 shl 11) OR (1 shl 63);
  //Mantisse kopieren
  move(tmpBArr[0],OutData[0],8);
  OutData[8] := lo(Exponent);
  OutData[9] := hi(Exponent);
  stream.write(OutData[0], 10);
End;

// Quelle: http://www.lazarusforum.de/viewtopic.php?f=9&t=9148
Function Read10ByteExtended(Const Stream: Tstream): Extended;
//Liest den TStream eines 10Byte extended (little Endian) gespeicherten Wertes
//aus und legt ihn in der 8-Byte variable ab.
const
  rezDW = 1/(256*256)/(256*256);
  rez64 = rezDW*rezDW;
Var
  Exponent: integer;
  data: Array[0..9] Of byte;
  dataDw: Array[0..1] of cardinal absolute data;
  //data64: UINt64 absolute data;
Begin
  stream.read(data, 10);
  //-1.0 or +1.0 //Integer( because otherwise intermidiate conversion to Int64 )
  result := Integer(1- Ord(data[9]>127)*2);
  //clear Sign Bit
  data[9] := data[9] And 127;
  // Calculate Exponent
  Exponent := ((data[9] Shl 8) Or data[8]) - 16382;
  result :=(dataDW[0]* rezDW+dataDW[1])*rezDW*result;
  //alternative Uint64
  //result := data64* rez64*result;
  result := result * power(2, Exponent);
End;
 
Yep, that's pretty much what I would have done. Though it will lose accuracy and cause detail loss in deep zooms, but you can't really help that if you're going to use the ARM's floating point unit, and a software solution would be agonisingly slow on the Pandora.

D.
 
Back
Top