Mandelbrot set: Difference between revisions

no edit summary
No edit summary
Line 5,849:
 
Pixmap.mandelbrot(300,300).save('mandel.ppm')</lang>
 
=={{header|Rust}}==
Dependencies: image, num-complex
<lang rust>extern crate image;
extern crate num_complex;
 
use std::fs::File;
use num_complex::Complex;
 
fn main() {
let max_iterations = 256u16;
let img_side = 800u32;
let cxmin = -2f32;
let cxmax = 1f32;
let cymin = -1.5f32;
let cymax = 1.5f32;
let scalex = (cxmax - cxmin) / img_side as f32;
let scaley = (cymax - cymin) / img_side as f32;
 
// Create a new ImgBuf
let mut imgbuf = image::ImageBuffer::new(img_side, img_side);
 
// Calculate for each pixel
for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
let cx = cxmin + x as f32 * scalex;
let cy = cymin + y as f32 * scaley;
 
let c = Complex::new(cx, cy);
let mut z = Complex::new(0f32, 0f32);
 
let mut i = 0;
for t in 0..max_iterations {
if z.norm() > 2.0 {
break;
}
z = z * z + c;
i = t;
}
 
*pixel = image::Luma([i as u8]);
}
 
// Save image
let fout = &mut File::create("fractal.png").unwrap();
image::ImageLuma8(imgbuf).save(fout, image::PNG).unwrap();
}</lang>
 
=={{header|Scala}}==
Anonymous user