# How to Plot a Mandelbulb

Hello,

I am trying to recreate the mandelbulb in processing (a 3D version of the mandelbrot set). I have looked through multiple sites for the equations to plot but they are different depending on the site. I am also struggling to actually plot the equations as-well (currently just plotting parallel lines). I know that it’s weird to plot using points but I’m really keen to understand the basics before making this project more complicated.

If anyone can give me some advice or pointers I would really appreciate it

``````/*
BY:       Callum Clegg
DATE:     Tuesday 25th August 2020
TITLE:    Mandelbulb
*/

// -----------------------------------START-----------------------------------
// ~variables
ArrayList<PVector> points = new ArrayList();

float i;

void setup() {
size(800, 800, P3D);
colorMode(HSB);

for (i = -50; i <= 50; i += 0.01) {
}

}

void draw() {
background(0);
translate(width/2, height/2, -850);

float hu = 0;
for (PVector v : points) {
stroke(hu+=0.1 * (i * 0.1), 180, 170);
strokeWeight(2);
point
(
v.x * 10,
v.y * 10,
v.z * 10
);
if(hu > 255) { hu = 0; }
}

}

void plot() {
noFill();

}

PVector mandlebulb(float x, float y, float z) {

/*
Calculating spherical coordinates.
source: https://en.wikipedia.org/wiki/Mandelbulb
*/

float r = sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2));
float theta = atan(y/x);
float phi = acos(z/r);

PVector v = new PVector(r, theta, phi);

return v;
}

// ------------------------------------END------------------------------------
``````

Is there another way to render this other then plotting points?
I really love 3d fractal´s but I never thought of it because when I coded a 2d mandelbrot (see here) I already saw that this renders very slow, let alone a 3d.
But I’m interested and found this page to give a bit more insight.
When I finish my current projects I definitely will look into this.

1 Like

Mikael Hvidtfeldt Christensen (Structure Synth and Fragmentarium projects) is a very interesting person to follow when it comes to 3D Fractals see this blog entry. Interestingly I found this shadertoy example might be possible to convert to run with processing.

OMG it was that simple, used Raphaël de Courville SableRaf/Shadertoy2Processing on shadertoy example

.

Needs refinement to remove unnecessary parameters, but hey it worked out of the tin…

4 Likes

Have not looked into it yet, but is it static?
If animated what frameRate did you get?

About 30 fps, on Linux Mint 5.4.0-42-generic. Hardware GeForce GT 730, driver NVidia-440.10, AMD A4-7300 APU. About 12 fps as a 1080, 720 sketch. Did you see how the sketch generated a job offer?

Do you just load a model or is it really calculated?

Ah, fun!

Both ~43fps at 1024x768 (Radeon RX560) with LWJGL backend via PraxisLIVE and JOGL backend in standard Processing 3.5.3. Been trying a few different types of sketch to ensure similar (if not better, but definitely not worse) performance via LWJGL.

I liked your name for it!

Yes, but I think you will have to be an expert in the GLSL language.
As soon as I’m done with current projects I will start to study this excellent OpenGL tutorial.
I wonder what the frameRate would be on a ordinary PC without an external video card.
Did you just copy the shader code of the link you gave above and saved it as explained in Processing’s Shaders tutorial?

1 Like

Initially I used Raphaël de Courville defaultShader, but then edited it to be more like the shaders by codeanticode.

See JRubyArt-example shader in data folder,

@noel @neilcsmith had this vague feeling that there was a Sunflow example, but also Fragmentarium of a Mandelbulb. But the sunflow turned out to be a sphereflake. May’be bub wasn’t such a good idea, apparently it might be equivalent to `bro` in US but kind of derogatory…

That made it really easy !
Only a frameRate of 6 on my modest PC, but still very nice.
I’m exited to learn GLSL now!