MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / julia

Function julia

24_raster_graphics/rust/thumbnail/src/main.rs:4–31  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2use std::path::PathBuf;
3
4fn julia() {
5 let imgx = 800;
6 let imgy = 800;
7
8 let scalex = 3.0 / imgx as f32;
9 let scaley = 3.0 / imgy as f32;
10
11 let mut imgbuf = image::ImageBuffer::new(imgx, imgy);
12
13 for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
14 let r = (0.3 * x as f32) as u8;
15 let b = (0.3 * y as f32) as u8;
16 let cx = y as f32 * scalex - 1.5;
17 let cy = x as f32 * scaley - 1.5;
18
19 let c = num_complex::Complex::new(-0.4, 0.6);
20 let mut z = num_complex::Complex::new(cx, cy);
21
22 let mut g = 0;
23 while g < 255 && z.norm() <= 2.0 {
24 z = z * z + c;
25 g += 1;
26 }
27 *pixel = image::Rgb([r, g, b]);
28 }
29
30 imgbuf.save("fractal.png").unwrap();
31}
32
33fn main() {
34 julia();

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected