triangle work

master
Able 2021-12-01 08:37:14 -06:00
parent 5260b5441e
commit 98b83c2e62
No known key found for this signature in database
GPG Key ID: 2BB8F62388A6A225
2 changed files with 19 additions and 3 deletions

View File

@ -32,8 +32,8 @@ impl AglApi for GraphicsRenderer {
let x2 = coords_end.x;
let y2 = coords_end.y;
let dx = x2 - x1;
let dy = y2 - y1;
let dx = x2.wrapping_sub(x1);
let dy = y2.wrapping_sub(y1);
for x in x1..x2 {
let y = y1 + dy * (x - x1) / dx;
@ -63,7 +63,9 @@ impl AglApi for GraphicsRenderer {
thickness: u32,
color: RGBA,
) {
todo!();
self.put_line(coords_1, coords_2, thickness, color);
self.put_line(coords_2, coords_3, thickness, color);
self.put_line(coords_3, coords_1, thickness, color);
}
fn paint_cursor(&mut self, coords: Point) {

View File

@ -83,6 +83,20 @@ fn main() {
},
"Hello".to_string(),
);
xyz.put_triangle(
Point { x: 10, y: 40 },
Point { x: 30, y: 100 },
Point { x: 10, y: 90 },
8,
RGBA {
r: 8,
g: 7,
b: 7,
a: 255,
},
);
// update pixels
for x in 0..600 * 400 {
buffer[x] = [xyz.buff[x].r, xyz.buff[x].g, xyz.buff[x].b, xyz.buff[x].a]