Comutare navigație
pbInfo.ro
Probleme
Probleme - clasa a IX-a
Probleme - clasa a X-a
Probleme - clasa a XI-a
Probleme din concursuri
Căutare problemă
Exerciții
Programează cu Blockly
Desenează cu Processing
Exersează SQL
Soluţii
Resurse
Resurse pentru clasa a IX-a
Resurse pentru clasa a X-a
Resurse pentru clasa a XI-a
Subiecte bacalaureat
Ajutor
Autentificare
Înregistrare
×
Autentificare
Utilizator sau email
Parola
Acest site foloseşte cookies. Navigând în continuare, vă exprimaţi acordul asupra folosirii cookie-urilor.
Îti place pbInfo? Atunci acceptă-l cu totul! Dezactivează modulul de blocare a reclamelor!
×
Lista scripturi
Script Nou
Ajutor
"Mandelbrot Set" - Processing
ID
Autor
Duplicat din
Ultima modificare
#4727
Arseniu Victor Stefan (Vicarsen)
-
Vineri, 31 dec 2021, 13:14
let width = 400; let height = 400; let centerX = -0.5; let centerY = 0.0; let zoom = 1.0; let max_iter = 50.0; let threshold = 256.0; class Complex { constructor(real, imaginary) { this.re = real; this.im = imaginary; } get length() { return Math.sqrt(this.re * this.re + this.im * this.im); } add(other) { return new Complex(this.re + other.re, this.im + other.im); } multiply(other) { return new Complex(this.re * other.re - this.im * other.im, this.re * other.im + this.im * other.re); } dot(other) { return this.re * other.re + this.im * other.im; } } function getColor(value) { if(value * 3.0 < 1.0) { let blue = color(0, 0, 255); let green = color(0, 255, 0); return lerpColor(blue, green, value * 3.0); } else if(value * 3.0 < 2.0) { let green = color(0, 255, 0); let red = color(255, 0, 0); return lerpColor(green, red, value * 3.0 - 1.0); } else { let red = color(255, 0, 0); let black = color(0, 0, 0); return lerpColor(red, black, value * 3.0 - 2.0); } } function setup() { createCanvas(width, height); for(let x = 0; x < width; x++) { for(let y = 0; y < height; y++) { let xmapped = map(x, 0, width, -1.0, 1.0); let ymapped = map(y, 0, height, -1.0, 1.0); let c = new Complex(xmapped / zoom + centerX, ymapped / zoom + centerY); let z = new Complex(0.0, 0.0); let iter = 0; while(iter < max_iter && c.length < threshold) { z = z.multiply(z).add(c); iter++; } let n = Math.log2(Math.log2(dot(z, z))) + 4.0; let cl = getColor(n / max_iter); set(x, y, cl); } } updatePixels(); } function draw() { }
Duplicare
Executare
Cod
×
Cod HTML
<iframe sandbox="allow-scripts" src="/p5js/index.php?id=4727" style="width:408px; height:408px;border:solid 1px gray; overflow: scroll;"></iframe>
×
Duplicare script
Denumirea noului script
Du-te sus!