From 299e45134e0090eaa630f693d070070e4245c135 Mon Sep 17 00:00:00 2001 From: serr Date: Tue, 24 Jun 2025 21:01:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=20=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D1=82=D1=8C=20turtle=20impl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 7 +------ src/turtle.rs | 8 ++++---- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7fdeb59..6c53778 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(); } diff --git a/src/turtle.rs b/src/turtle.rs index d6feae6..a03ffdd 100644 --- a/src/turtle.rs +++ b/src/turtle.rs @@ -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, }