~jpl8/piet_interpreter

dac2df8104948cf3309a9345ddfd39e4003c86d7 — jpl 2 years ago fafcd48
first working version
5 files changed, 32 insertions(+), 9 deletions(-)

M Cargo.toml
A images/Piet_hello_big.png
M src/interpreter/mod.rs
M src/main.rs
M src/rules.rs
M Cargo.toml => Cargo.toml +1 -1
@@ 1,6 1,6 @@
[package]
name = "piet"
version = "0.1.0"
version = "0.2.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

A images/Piet_hello_big.png => images/Piet_hello_big.png +0 -0
M src/interpreter/mod.rs => src/interpreter/mod.rs +26 -2
@@ 54,6 54,29 @@ impl Interpreter {
       }

    }

    pub fn debug(&mut self) -> io::Result<()> {

       loop {
            let curr = self.head.pos();
            if let Some(next) = self.move_next() {

                let curr_codel = self.img().get(curr.0, curr.1);
                let next_codel = self.img().get(next.0, next.1);

                println!("In: {:?}, Next: {:?}, Op: {:?}", curr, next, rules::get_op(&curr_codel, &next_codel)); 

                self.do_op(&curr_codel, &next_codel)?;

            }

            else { return Ok(()) }

       }

    }
 

    fn do_op(&mut self, curr: &Codel, next: &Codel) -> io::Result<()> {

        // error = Err(Error::new(ErrorKind::InvalidInput, "ERROR"));


@@ 315,8 338,8 @@ impl Interpreter {
                }
                else { 
                    cc_switches += 1;
                    self.head.codel_chooser = self.head.codel_chooser.toggle(); 
                }
                self.head.codel_chooser = self.head.codel_chooser.toggle(); 
                tries += 1;
            }



@@ 352,7 375,8 @@ impl Interpreter {
            }
        }
    }

    
    #[allow(dead_code)]
    fn reset(&mut self) {
            self.img.reset_block_sizes();
            self.img.update_block_sizes();

M src/main.rs => src/main.rs +4 -5
@@ 1,10 1,9 @@
use piet::translator;
use piet::interpreter::{Interpreter};

fn main() {
   
    let mut img = translator::png_to_piet_img("images/test_piet.png").unwrap();
    img.update_block_sizes();
    println!("{:#?}", img);
    let mut interpreter = Interpreter::new("images/Piet_hello_big.png").unwrap();
    interpreter.exec().expect("Execution Failed!");

}



M src/rules.rs => src/rules.rs +1 -1
@@ 1,6 1,6 @@
use crate::piet_img::Codel;
use crate::color::Color;

#[derive(Debug)]
pub enum Op {
    Push,
    Pop,