Mandelbrot

Previous topic - Next topic

MrTAToad

Have been looking at old versions of this site, and, fortunately enough some of the demo programs were available (which is unusual for the Wayback Machine).  One interesting program was a Mandelbrot example.

Its interesting to note that running this on a AMD graphics processor results in the BlitzBasic version running a bit faster than the GLBasic version, but on a nVidia machine it is the other way around.

I couldn't get the DBPro or DarkBasic version to run (the former just crashes - which is to be expected :) ) and the latter requires d3drm.dll to be installed, but I'm not bothering with.

The C version is slow because its all GDI stuff - using DirectX it would equal the GLBasic version (at least).

The second picture is the original GLBasic version - no idea why the display is strange (again, it could be an AMD problem).

MrTAToad

So what about using Triority, I hear no-one cry.

Well, I converted the GLBasic code and got it running well, and is somewhat faster (probably because it uses DirectX and not OpenGL) - whether it will be the same on an nVidia machine, I dont know.

Originally thought, it was half the speed of GLBasic!  It turns out that my SETPIXEL routine was calling the line drawing routine for 1 pixel, which apparently in computationally expensive - change it to use the SDL2 routine for pixel plotting and I got the correct speed.


Hemlos

If im not mistaking mandrelbrot is an algorithm, which is used to benchtest.
The algorithm includes some drawing routines.
It is possible that the algorithm calls for a pixel to be drawn.

I posted a shader version of this, i believe its in the bonus section.
Bing ChatGpt is pretty smart :O

MrTAToad

Very impressive - haven't seen that before.

Hemlos

Actually i will be updating that code, its not 100% correct....minor issues, missing redundant(yet politically correct) identifiers.
Bing ChatGpt is pretty smart :O

backslider


MrTAToad

#6
I tried this on the App Game Kit 2 system - but it's so slow that it takes several seconds to display several pixels... =D

Here is the code by the way :

Code (glbasic) Select
// --------------------------------- //
// Project: Mandelbrot - Speedtest
// Start: Tuesday, September 09, 2003
// IDE Version: 1.30906


_MAX = 128   // _MAX iterations
SX = -2.025 // start value real
SY = -1.125 // start value imaginary
EX = 0.6    // end value real
EY = 1.125  // end value imaginary

x1 = 640    // ScreenX
y1 = 480    // ScreenY
xy = x1 / y1// x/y-ratio

SETSCREEN x1,y1,FALSE

xstart = SX
ystart = SY
xende = EX
yende = EY

xzoom = (xende - xstart) / x1
yzoom = (yende - ystart) / y1
fac=0.99
WHILE TRUE
xende = xende*fac
xstart=xstart*fac
ystart=ystart*fac
yende=yende*fac
xzoom = (xende - xstart) / x1
yzoom = (yende - ystart) / y1
mandelbrot()
PRINT "Speed: " + INTEGER(x1*y1 / (1+(GETTIMER()))) + " Kpix/sec", 0, 0
SHOWSCREEN
WEND
END

// ------------------------------------------------------------- //
// -=#  Mandelbrot  #=-
// ------------------------------------------------------------- //
FUNCTION mandelbrot: // calculate all points
LOCAL x, y, h, b, old=0, col
FOR x = 0 TO x1-1
FOR y = 0 TO y1-1
h = DotsColor(xstart + xzoom * x, ystart + yzoom * y) // color value
IF h <> old
b = 1.0 - h * h // brightness
col = HSB2RGB(h, 0.8, b)
old = h;
ENDIF
SETPIXEL x, y, col
NEXT
NEXT
ENDFUNCTION


// ------------------------------------------------------------- //
// -=#  DotsColor  #=-
// ------------------------------------------------------------- //
FUNCTION DotsColor: xval, yval // color value from 0.0 to 1.0 by iterations
LOCAL r=0, i=0, j=0, m=0

WHILE (j < _MAX) AND (m < 4.0)
//j=j+1
INC j
m = r * r - i * i
i = 2.0 * r * i + yval
r = m + xval
WEND
RETURN j / _MAX
ENDFUNCTION



// ------------------------------------------------------------- //
// -=#  HSB2RGB  #=-
// ------------------------------------------------------------- //
FUNCTION HSB2RGB: hue, saturation, brightness
LOCAL red, green, blue, domainOffset// hue mod 1/6
IF brightness = 0
RETURN 0
ELSEIF saturation = 0
RETURN RGB(brightness*255, brightness*255, brightness*255)
ENDIF

SELECT hue
CASE < 1.0/6
// red domain; green ascends
domainOffset = hue
red   = brightness
blue  = brightness * (1.0 - saturation)
green = blue + (brightness - blue) * domainOffset * 6
CASE < 2.0/6
// yellow domain; red descends
domainOffset = hue - 1.0/6
green = brightness
blue  = brightness * (1.0 - saturation)
red   = green - (brightness - blue) * domainOffset * 6
CASE < 3.0/6
// green domain; blue ascends
domainOffset = hue - 2.0/6
green = brightness
red   = brightness * (1.0 - saturation)
blue  = red + (brightness - red) * domainOffset * 6
CASE < 4.0/6
// cyan domain; green descends
domainOffset = hue - 3.0/6
blue  = brightness
red   = brightness * (1.0 - saturation)
green = blue - (brightness - red) * domainOffset * 6
CASE < 5.0/6
// blue domain; red ascends
domainOffset = hue - 4.0/6
blue  = brightness
green = brightness * (1.0 - saturation)
red   = green + (brightness - green) * domainOffset * 6
DEFAULT
// magenta domain; blue descends
domainOffset = hue - 5.0/6
red   = brightness
green = brightness * (1.0 - saturation)
blue  = red - (brightness - green) * domainOffset * 6
ENDSELECT
RETURN RGB(red*255, green*255, blue*255)
ENDFUNCTION