From 6262cd9aab04bce1c98fd5f6ab19cd5da814dfc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 11 Jan 2021 08:42:04 -0300 Subject: Implement add and sub for P --- src/main.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 8c23d3e..e5e4112 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,9 @@ mod poly; +mod number; mod lerp; -use crate::poly::Number; -use crate::lerp::Lerp; +use number::Number; +use lerp::Lerp; use std::thread; use std::time::Duration; @@ -13,10 +14,12 @@ use sdl2::keyboard::Keycode; use sdl2::rect::Rect; fn main() { - let a = Lerp::new(vec![100.0, 200.0, 300.0, 500.0]); - let b = Lerp::new(vec![400.0, 140.0, 500.0, 300.0]); - let pa = lerp::lp(a); - let pb = lerp::lp(b); + //let a = Lerp::new(vec![2.0, -2.0, 2.0]); + //let b = Lerp::new(vec![-1.0, 1.0, 2.0]); + //let pa = lerp::lp(a); + //let pb = lerp::lp(b); + let pa = vec![1.0, 5.0, -2.0]; + let pb = vec![5.0, -4.0, 0.0]; let p = poly::gcd(&pa, &pb); let sdl_context = sdl2::init().unwrap(); @@ -43,16 +46,20 @@ fn main() { } } - for t in 0..800 { - let x = poly::eval_poly(&pa, t as Number / 800.0); - let y = poly::eval_poly(&pb, t as Number / 800.0); - let z = poly::eval_poly(&p, t as Number / 800.0); + let s = -600.0 / 10.0; + let k = 600.0 / 2.0; + for t in -800..800 { + let x = k + s * poly::eval_poly(&pa, t as Number / 100.0); + let y = k + s * poly::eval_poly(&pb, t as Number / 100.0); + let z = k + s * poly::eval_poly(&p, t as Number / 100.0); canvas.set_draw_color(Color::RGB(180, 20, 20)); - canvas.fill_rect(Rect::new(t, x as i32, 5, 5)).unwrap(); + canvas.fill_rect(Rect::new(400 + t, x as i32, 5, 5)).unwrap(); canvas.set_draw_color(Color::RGB(20, 180, 20)); - canvas.fill_rect(Rect::new(t, y as i32, 5, 5)).unwrap(); + canvas.fill_rect(Rect::new(400 + t, y as i32, 5, 5)).unwrap(); canvas.set_draw_color(Color::RGB(20, 20, 180)); - canvas.fill_rect(Rect::new(t, z as i32, 5, 5)).unwrap(); + canvas.fill_rect(Rect::new(400 + t, z as i32, 2, 2)).unwrap(); + canvas.set_draw_color(Color::RGB(255, 0, 0)); + canvas.fill_rect(Rect::new(400 + t, k as i32, 2, 2)).unwrap(); } canvas.present(); -- cgit v1.2.3