1use crate::display::Display;
2use anyhow::Result;
3type Point = (isize, isize);
6
7pub fn fill(display: &mut Display, value: u8) {
9 display.memory.iter_mut().for_each(|mem| *mem = value);
10}
11
12pub fn draw_point(display: &mut Display, point: Point, color: u8) {
14 let index = point.0 + (point.1 / 8) * display.width as isize;
15 display.memory[index as usize] = color;
16}
17
18pub fn draw_line(display: &mut Display, (x1, y1): Point, (x2, y2): Point) {
19 let dx = (x2 - x1).abs();
20 let dy = (y2 - y1).abs();
21
22 let mut x = x1;
23 let mut y = y1;
24
25 let x_inc = if x2 > x1 { 1 } else { -1 };
26 let y_inc = if y2 > y1 { 1 } else { -1 };
27
28 let mut error = dx - dy;
29
30 while x != x2 || y != y2 {
31 draw_point(display, (x, y), 0xFF);
32
33 let double_error = error * 2;
34
35 if double_error > -dy {
36 error -= dy;
37 x += x_inc;
38 }
39
40 if double_error < dx {
41 error += dx;
42 y += y_inc;
43 }
44 }
45
46 draw_point(display, (x2, y2), 0xFF);
47}
48
49
50pub fn clear(display: &mut Display) -> Result<()> {
52 fill(display, 0x00);
53
54 Ok(())
55}