diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-11 08:42:04 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2021-01-11 08:42:04 -0300 |
commit | 6262cd9aab04bce1c98fd5f6ab19cd5da814dfc7 (patch) | |
tree | 6ddb856d1e11ebea1bc12771b98623dc30070b2a /src/main.rs | |
parent | 7fa34698ba8ee80227fa0b8eaab7a7382a5cf465 (diff) | |
download | bezier-6262cd9aab04bce1c98fd5f6ab19cd5da814dfc7.tar.gz bezier-6262cd9aab04bce1c98fd5f6ab19cd5da814dfc7.zip |
Implement add and sub for P
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 33 |
1 files changed, 20 insertions, 13 deletions
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(); |