-2

I have a question related to the fractal example (section '6.2 Generating Fractals', https://github.com/PistonDevelopers/image) in examples supplied for image crate

1) At line

image::ImageLuma8(imgbuf).save(fout, image::PNG).unwrap();

I get the following compile error message (rustc 1.25.0):

error[E0061]: this function takes 1 parameter but 2 parameters were supplied
  --> src/main.rs:52:31
   |
52 |     image::ImageLuma8(imgbuf).save(fout, image::PNG).unwrap();
   |                               ^^^^ expected 1 parameter

Thank you for helping!

2) Note in addition that I had to change

use num_complex::Complex;

to

use num::complex::{Complex};

at the beginning of the example. Maybe crate num_complex does not exist any longer ?

TC29
  • 1
  • 2
  • 1
    open on issue on the github would be more logical, SO is not a support service... the doc is updated, https://docs.rs/image/0.19.0/image/struct.ImageBuffer.html#method.save. – Stargateur May 11 '18 at 11:59
  • 1
    Please provide a more adequate [MCVE]. Content behind links are very likely to change in the future. What's important here: all relevant dependencies' versions in use, plus a minimal version of that example _in the question itself_. If the compiler error can be reproduced in the [Rust Playground](//play.rust-lang.org), that is a plus. – E_net4 May 11 '18 at 12:06
  • Sorry Stargateur ! I am a newbie here and did not know I am not supposed to ask this kind of question. Thank you for the link. – TC29 May 11 '18 at 13:09
  • Thank you E_net4! Rust playground gave me the same error as in my comments. It seems that the code in example on https://github.com/PistonDevelopers/image was not up to date. – TC29 May 11 '18 at 13:23
  • I actually ran the example on the `master` branch and it compiled and ran just fine. There is probably something different going on in your build. Consider editing your question with all the necessary details, for there's still a chance that it could be salvaged. – E_net4 May 11 '18 at 20:04

1 Answers1

1

In the section "6.2 Generating Fractals" of PistonDevelopers, the original example cannot be compiled successfully. It seems there are some outdated parameters setting, here is an updated version. hope this help.

//! An example of generating julia fractals.
extern crate image;
extern crate num;

use self::num::Complex;
use std::path::Path;

fn main() {
    let max_iterations = 256u16;

    let imgx = 800;
    let imgy = 800;

    let scalex = 4.0 / imgx as f32;
    let scaley = 4.0 / imgy as f32;

    // let mut y = 0;
    // Create a new ImgBuf with width: imgx and height: imgy
    let mut imgbuf: image::GrayImage = image::ImageBuffer::new(imgx, imgy);

    // Iterate over the coordinates and pixels of the image
    for (x, y, pixel) in imgbuf.enumerate_pixels_mut() {
        let cy = y as f32 * scaley - 2.0;
        let cx = x as f32 * scalex - 2.0;

        let mut z = Complex::new(cx, cy);
        let c = Complex::new(-0.4, 0.6);

        let mut i = 0;

        for t in 0..max_iterations {
            if z.norm() > 2.0 {
                break;
            }
            z = z * z + c;
            i = t;
        }

        // Create an 8bit pixel of type Luma and value i
        // and assign in to the pixel at position (x, y)
        *pixel = image::Luma([i as u8]);
    }

    // Save the image as “fractal.png”
    let path = Path::new("fractal.png");

    // We must indicate the image's color type and what format to save as
    image::ImageLuma8(imgbuf).save(path).unwrap();
}
madeinQuant
  • 1,721
  • 1
  • 18
  • 29