From b21e39511e118de6b60d2479e1a764172ad2c1c4 Mon Sep 17 00:00:00 2001 From: Vincent Ollivier Date: Wed, 16 Oct 2024 19:41:31 +0200 Subject: [PATCH] Rename variables --- src/bin/mandelbrot.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/bin/mandelbrot.rs b/src/bin/mandelbrot.rs index 069b5087..67028aed 100644 --- a/src/bin/mandelbrot.rs +++ b/src/bin/mandelbrot.rs @@ -34,27 +34,27 @@ fn palette(color: bool) -> [u8; 768] { fn mandelbrot(buffer: &mut [u8], x_offset: f64, y_offset: f64, zoom: f64) { let x_scale = 3.0 / 320.0 / zoom; let y_scale = 2.0 / 200.0 / zoom; - for y in 0..200 { - for x in 0..320 { + for py in 0..200 { + for px in 0..320 { // Map pixel position to complex plane - let cx = x as f64 * x_scale - 2.0 + x_offset; - let cy = y as f64 * y_scale - 1.0 + y_offset; + let x0 = px as f64 * x_scale - 2.0 + x_offset; + let y0 = py as f64 * y_scale - 1.0 + y_offset; // Compute whether the point is in the Mandelbrot Set - let mut zx = 0.0; - let mut zy = 0.0; + let mut x = 0.0; + let mut y = 0.0; let mut i = 0; let n = 255; - while zx * zx + zy * zy < 4.0 && i < n { - let tmp = zx * zx - zy * zy + cx; - zy = 2.0 * zx * zy + cy; - zx = tmp; + while x * x + y * y <= 4.0 && i < n { + let tmp = x * x - y * y + x0; + y = 2.0 * x * y + y0; + x = tmp; i += 1; } // Color the pixel based on the number of iterations - buffer[y * 320 + x] = i as u8; + buffer[py * 320 + px] = (i % 256) as u8; } } }