summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs
index 8831976..8c23d3e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,28 +1,22 @@
-use poly::Poly;
-use poly::Number;
-use poly::Lerp;
+mod poly;
+mod lerp;
-use sdl2::pixels::Color;
-use sdl2::event::Event;
-use sdl2::keyboard::Keycode;
-use sdl2::rect::Rect;
+use crate::poly::Number;
+use crate::lerp::Lerp;
use std::thread;
use std::time::Duration;
-fn eval_poly(p: &Poly, t: Number) -> Number {
- let mut r = 0.0;
- for i in 0..p.len() {
- r += p[i] * t.powi(i as i32);
- }
- r
-}
+use sdl2::pixels::Color;
+use sdl2::event::Event;
+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 = poly::lp(a);
- let pb = poly::lp(b);
+ let pa = lerp::lp(a);
+ let pb = lerp::lp(b);
let p = poly::gcd(&pa, &pb);
let sdl_context = sdl2::init().unwrap();
@@ -50,9 +44,9 @@ fn main() {
}
for t in 0..800 {
- let x = eval_poly(&pa, t as Number / 800.0);
- let y = eval_poly(&pb, t as Number / 800.0);
- let z = eval_poly(&p, t as Number / 800.0);
+ 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);
canvas.set_draw_color(Color::RGB(180, 20, 20));
canvas.fill_rect(Rect::new(t, x as i32, 5, 5)).unwrap();
canvas.set_draw_color(Color::RGB(20, 180, 20));