#[derive(Debug, Clone, Copy)]
pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl Color {
pub const WHITE: Self = Self {
r: 255,
g: 255,
b: 255,
};
pub const BLACK: Self = Self { r: 0, g: 0, b: 0 };
pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
Self { r, g, b }
}
}
#[derive(Debug, Clone)]
pub enum DrawCommand {
Clear(Color),
FilledPolygon {
vertices: Vec<(f32, f32)>,
color: Color,
},
FilledCircle {
x: f32,
y: f32,
radius: f32,
color: Color,
},
Line {
x1: f32,
y1: f32,
x2: f32,
y2: f32,
color: Color,
},
Polyline {
points: Vec<(f32, f32)>,
color: Color,
},
}
#[derive(Debug, Clone)]
pub struct DrawList {
pub commands: Vec<DrawCommand>,
pub width: u32,
pub height: u32,
}
impl DrawList {
pub fn new(width: u32, height: u32) -> Self {
Self {
commands: Vec::new(),
width,
height,
}
}
pub fn push(&mut self, cmd: DrawCommand) {
self.commands.push(cmd);
}
}
pub fn rotate_point(x: f64, y: f64, angle: f64) -> (f64, f64) {
let (sin, cos) = angle.sin_cos();
(x * cos - y * sin, x * sin + y * cos)
}