Mandelbrot Fractal
How do I make an mandelbrot fractal?
Simple Mandelbrot fractal in JavaScript.. What is a mandelbrot fractal? How do you make a mandelbrot fractal? This script and codes were developed by Billy Brown on 29 September 2022, Thursday.
Mandelbrot Fractal - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Mandelbrot Fractal</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas data-js="canvas" width="500" height="500"></canvas> <script src="js/index.js"></script>
</body>
</html>
Mandelbrot Fractal - Script Codes CSS Codes
* { margin: 0; padding: 0; }
html { background-color: black; }
Mandelbrot Fractal - Script Codes JS Codes
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Complex = function () { function Complex(real, imaginary) { _classCallCheck(this, Complex); this.r = real; this.i = imaginary; } Complex.prototype.add = function add(that) { return new Complex(this.r + that.r, this.i + that.i); }; Complex.prototype.mult = function mult(that) { return new Complex(this.r * that.r - this.i * that.i, this.r * that.i + this.i * that.r); }; return Complex;
}();
var canvas = document.querySelector('[data-js="canvas"]');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var ctx = canvas.getContext('2d');
var scale = 750;
draw();
window.onresize = draw;
function draw() { var z = new Complex(0, 0); var c = new Complex(1, 0); for (var x = 0; x < canvas.width; ++x) { for (var y = 0; y < canvas.height; ++y) { var green = 255; for (var i = 0; i < 255; i++) { z = z.mult(z).add(c); if (z.r > 2 || z.r < -2 || z.i > 2 || z.i < -2) { green = i; break; } } ctx.fillStyle = 'rgb(0, ' + green + ', 0)'; ctx.fillRect(x, y, 1, 1); z = new Complex(x / scale, y / scale); c = new Complex(x / scale, y / scale); } }
}
Developer | Billy Brown |
Username | _Billy_Brown |
Uploaded | September 29, 2022 |
Rating | 3.5 |
Size | 2,706 Kb |
Views | 14,168 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
CSS-Tricks lodge button | 3,247 Kb |
Chaos | 1,660 Kb |
Slideout Sidebar | 3,596 Kb |
Pure CSS image slider | 2,256 Kb |
Group Contact Form | 3,150 Kb |
A Pen by Billy Brown | 1,824 Kb |
Single-element Twitter button | 3,173 Kb |
Number game | 3,790 Kb |
Aperture-style lens | 3,703 Kb |
Playing with FlexBox | 3,162 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Simple Buttons | Haydenmills | 1,750 Kb |
C.Rowe Button | Brownerd | 2,473 Kb |
CSS3 iPad | Vikvarg | 1,766 Kb |
Halo 5 REQ Guide Bookmarklet | Cwacht | 3,993 Kb |
700 Synapses Per Second | Silentkrange | 2,138 Kb |
Pure CSS Menu | Bronsrobin | 3,321 Kb |
03 - CSS Variables | Run-time | 2,682 Kb |
Free css icon set v2 - one div | Ben_jammin | 0 Kb |
Awesome Full Page Menu Nav | Ey_intuitive | 4,194 Kb |
Buttons for autumn | Nikazawila | 1,795 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!