~jpl8/text-to-piet

073731416482905a9dc419291cee73484927e81e — jpl 1 year, 6 months ago b26f1cd
Refactor terminator placement.
2 files changed, 24 insertions(+), 21 deletions(-)

M src/main.rs
M test.png
M src/main.rs => src/main.rs +24 -21
@@ 244,27 244,7 @@ fn colors_to_img(colors: Vec<Color>, img_size: u32) -> RgbImage {
    }

    // Add terminator
    {
        img.put_pixel(x, y, Rgb(color.to_bytes()));

        let color = colors::instruction_to_color(PUSH(1), *color);
        (x, y) = update_x_y_spiral(x, y, 1, &final_dir.clockwise());
        img.put_pixel(x, y, Rgb(color.to_bytes()));

        let color = colors::instruction_to_color(PUSH(1), color);
        (x, y) = update_x_y_spiral(x, y, 1, &final_dir.clockwise());
        img.put_pixel(x, y, Rgb(color.to_bytes()));

        (x, y) = update_x_y_spiral(x, y, 1, &final_dir);
        img.put_pixel(x, y, Rgb(color.to_bytes()));

        (x, y) = update_x_y_spiral(x, y, 2, &final_dir.clockwise().clockwise());
        img.put_pixel(x, y, Rgb(color.to_bytes()));

        (x, y) = update_x_y_spiral(x, y, 1, &final_dir);
        (x, y) = update_x_y_spiral(x, y, 1, &final_dir.clockwise());
        img.put_pixel(x, y, Rgb(color.to_bytes()));
    }
    add_terminator(&mut img, final_pos, color, &final_dir);

    //img.save(img_name).expect("Failed to save image");
    img


@@ 282,3 262,26 @@ fn get_rect(sides: (u32, u32), start: (u32, u32), dir: &Direction) -> Vec<(u32, 
    }
    blocks
}

fn add_terminator(img: &mut RgbImage, pos: (u32, u32), color: &Color, dir: &Direction) {
    let (mut x, mut y) = pos;
    img.put_pixel(x, y, Rgb(color.to_bytes()));

    let color = colors::instruction_to_color(PUSH(1), *color);
    (x, y) = update_x_y_spiral(x, y, 1, &dir.clockwise());
    img.put_pixel(x, y, Rgb(color.to_bytes()));

    let color = colors::instruction_to_color(PUSH(1), color);
    (x, y) = update_x_y_spiral(x, y, 1, &dir.clockwise());
    img.put_pixel(x, y, Rgb(color.to_bytes()));

    (x, y) = update_x_y_spiral(x, y, 1, &dir);
    img.put_pixel(x, y, Rgb(color.to_bytes()));

    (x, y) = update_x_y_spiral(x, y, 2, &dir.clockwise().clockwise());
    img.put_pixel(x, y, Rgb(color.to_bytes()));

    (x, y) = update_x_y_spiral(x, y, 1, &dir);
    (x, y) = update_x_y_spiral(x, y, 1, &dir.clockwise());
    img.put_pixel(x, y, Rgb(color.to_bytes()));
}

M test.png => test.png +0 -0