Public
Edited
Jul 23, 2023
Insert cell
md`# Mandelbrot with ganja.js EDIT: hyperbolic, , ...

Using [ganja.js](https://github.com/enkimute/ganja.js) for complex numbers and graphing.

https://raw.githubusercontent.com/enkimute/ganja.js/master/ganja.js
https://github.com/enkimute/ganja.js/blob/master/ganja.js#L108


`
Insert cell
Algebra(1,0,()=>{
return this.graph((x,y)=>{
var n= 4 // 3
var c=x*4+y*4e1;
// var n=3, z=0e1, c=x*4+y*4e1;
var z=0e1
while (z < 10 && n--) {
//z=z.Conjugate*z*z*z*z*z*z*z+c;
z=z*z*z.Conjugate*z*z*z*z*z+c;
/////z=z*z*z*z*z*z*z*z+c;
} //z**3+c; //z**2+c;
return (n/10);
},
{ width:512, height:512}
);
})
Insert cell
Insert cell
//

// In quaternion space H, we calculate the mandelbrot set and use the
// iteration count for colorisation.

Algebra(0,2,()=>{
return (this.graph((x,y)=>{
//document.body.appendChild

// Calculate iteration count for mandelbrot.
var n= 10 // 8 // 4 // 3 // 2 // 1 // 6 //5 //4 // 3 //1 // 2 //10 // Iteration count.
var z=0e12, // A complex number Z.
c=x*1.75-1+y*1e12 // position in the complex plane.
//var axis=0.578*(1e1+1e2+1e12) // The 1,1,1 axis.
//var axis=0.9*(1e1+1e2+1e12) // The 1,1,1 axis.
var axis=1*(1e1+1e2+1e12) // The 1,1,1 axis.
// See if this c escapes ..
while (z < 4 && n--) z=z**2+c;


//z=c
//z=z*z
x=z.s
y=(z* 1e12).s
// Smooth iteration count and angle added in.
//n += Math.log2(Math.log2(Math.max(4,z.Length)))-Math.atan2(y,x)*10;
//n =z.Length
n = Math.atan2(y,x)*10;
// Use the iteration count to rotate the color red in the hue plane
var red=1e1,
rot=Math.cos(n/20) + Math.sin(n/20)*axis;

// url
//#Hcomplex(w)
// Rotate red around the 1,1,1 axis and return the resulting color
//var col= 0.2*(rot*red*rot.Conjugate)+ 0.8 * axis
var colll= (rot*red*rot.Conjugate) - axis

// S = s * np.ones(H.shape)
////var modul = colll.Length /10
var modul = z.Length // /10
//modul = np.linalg.norm(w , axis=(2))
//#np.absolute(w)

var V = (1.0-1.0/(1+modul**2)) ** 0.5 //** 2 //** 0.5 //#0.2

//HSV = np.dstack((H, S, V))
//RGB = hsv_to_rgb(HSV)
//var col= 0.1*(rot*red*rot.Conjugate)+ 0.9 * axis
//var col= axis + V * colll
var col= axis + (1-V) * colll
return col.slice(1,4);
////return col.slice(1,3);

}));

});
Insert cell
// In quaternion space H, we calculate the mandelbrot set and use the
// iteration count for colorisation.

Algebra(1,2,()=>{
return (this.graph((x,y)=>{
//document.body.appendChild

// Calculate iteration count for mandelbrot.
var n=10, // Iteration count.
z=0e12, // A complex number Z.
c=x*1.75-1+y*1e12, // position in the complex plane.
axis=0.578*(1e1+1e2+1e12); // The 1,1,1 axis.
// See if this c escapes ..
while (z < 4 && n--) z=z**2+c;
// Smooth iteration count and angle added in.
n += Math.log2(Math.log2(Math.max(4,z.Length)))-Math.atan2(y,x)*10;
// Use the iteration count to rotate the color red in the hue plane
var red=1e1,
rot=Math.cos(n/20) + Math.sin(n/20)*axis;
// Rotate red around the 1,1,1 axis and return the resulting color
return (rot*red*rot.Conjugate).slice(1,4);

}));

});
Insert cell
Algebra = require('ganja.js')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more