Once you have the code for a Mandelbrot fractal, making the Julia fractal is easy!
Log in to post a comment.
Canvas.setpenopacity(1);
const turtle = new Turtle();
turtle.penup();
class ComplexNumber{
constructor(real, im){
this.r = real || 0.0;
this.i = im || 0.0;
}
pow2(){
let a = this.r;
let b = this.i;
this.r = a * a - b * b;
this.i = 2 * (a * b);
return this;
}
len(){
return Math.sqrt(this.r * this.r + this.i * this.i);
}
times(k){
this.r *= k;
this.i *= k;
return this;
}
add(complex){
this.r += complex.r;
this.i += complex.i;
return this;
}
}
function pixel(i,j){
let k;
let x = i / 100;
let y = j / 100;
let z = new ComplexNumber(x,y);
// Here are the fun values to change !!!
let c = new ComplexNumber(-0.86,0.2);
z.times(1.8);
for(k = 0; k < 25; k++){
z = z.pow2().add(c);
if(z.len() > 4.0){
break;
}
}
turtle.goto(i, j + 0.6); // Maybe remove the 0.6 for better printing !!!
if(z.len() < 3.0 && z.len()){
turtle.pendown();
turtle.goto(i,j);
} else {
turtle.penup();
}
}
function walk(i) {
let ii = i * 2.6 + 10;
pixel(ii % 200 - 100, (ii - ii % 200) / 100 - 100);
return i < 75 * 75;
}