~jpl8/text-to-piet

957ebe4c22a320e346008ae904693d8d4e1bb23c — jpl 1 year, 7 months ago 5223284
Improve img_size estimation
3 files changed, 14 insertions(+), 2 deletions(-)

A resources/OrangeShow.txt
M src/main.rs
M test.png
A resources/OrangeShow.txt => resources/OrangeShow.txt +5 -0
@@ 0,0 1,5 @@
I fell in love at the Orange Show Speedway.
It didn't look like this three years ago.
I had it all at the Orange Show Speedway
Or some place like that, it all looks the same.
Everything changes, what a shame.

M src/main.rs => src/main.rs +9 -2
@@ 192,14 192,21 @@ fn expected_size(instructions: &Vec<Instructions>) -> u32 {
    // len_spiral(side) = floor(side²/2)

    // num_blocks <= len_spiral
    // n + 2 * (side - 3) <= floor(side²/2)
    let num_blocks = instructions.iter().fold(0, |acc, x| {
        acc + match x {
            PUSH(n) => *n,
            _ => 1,
        }
    });

    // solving for side should work out to

    //4 + (((2 * n - 8) as f64).sqrt() as u32) + 1
    //2 + ((2 * n - 8) as f64).sqrt() as u32
    //3 + ((2 * n - 9) as f64).sqrt() as u32
    10 + ((2.5 * (n as f64)) as f64).sqrt() as u32
    //10 + ((2.5 * (num_blocks as f64)) as f64).sqrt() as u32
    //2 + ((2 * num_blocks - 8) as f64).sqrt() as u32
    4 + (((2 * num_blocks - 8) as f64).sqrt() as u32) + 1
}

fn instructions_to_blocks(instructions: &Vec<Instructions>, img_size: u32) -> Vec<Color> {

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