начал писать turtle impl

main
serr 2025-06-24 21:01:56 +03:00
parent 0889732c25
commit 299e45134e
2 changed files with 5 additions and 10 deletions

View File

@ -3,12 +3,7 @@ mod turtle;
use turtle::Turtle;
fn main() {
let mut turtle = Turtle::new();
println!("Pos = {:?}", turtle.position());
let start = (50, 50);
let end = (200, 200);
turtle.draw_line(start, end);
turtle.draw_line((50, 50), (200, 200));
turtle.save("output.png").unwrap();
}

View File

@ -10,11 +10,12 @@ type Coord = (i32, i32);
const DEFAULT_WIDTH: u32 = 800;
const DEFAULT_HEIGHT: u32 = 800;
const DEFAULT_BACKGROUND_COLOUR: Colour = Rgb([255u8, 255u8, 255u8]);
const DEFAULT_COLOUR: Colour = Rgb([0u8, 0u8, 0u8]);
pub struct Turtle {
buf: ImgBufU8,
colour: Colour,
background_colour: Colour,
pos: Coord,
angle: f64,
}
@ -23,13 +24,12 @@ impl Turtle {
pub fn new() -> Self {
let mut buf = ImageBuffer::new(DEFAULT_WIDTH, DEFAULT_HEIGHT);
for pixel in buf.pixels_mut() {
*pixel = Rgb([255u8, 255u8, 255u8]);
*pixel = DEFAULT_BACKGROUND_COLOUR;
}
Turtle {
buf,
colour: Rgb([0u8, 0u8, 0u8]),
background_colour: Rgb([255u8, 255u8, 255u8]),
colour: DEFAULT_COLOUR,
pos: (0, 0),
angle: 0.0,
}