diff options
| author | brian cully <bjc@spork.org> | 2025-12-29 14:32:30 -0500 |
|---|---|---|
| committer | brian cully <bjc@spork.org> | 2025-12-29 14:32:30 -0500 |
| commit | 65d1301072a7f9223ce2ffe420b6f2784b8bbe04 (patch) | |
| tree | c20667f8241a0211a23d6676213ea44843bbfb44 /src/state.rs | |
| parent | 316286b8b65ac5a7abf5117dc942a70b94e1be53 (diff) | |
| download | polyring-65d1301072a7f9223ce2ffe420b6f2784b8bbe04.tar.gz polyring-65d1301072a7f9223ce2ffe420b6f2784b8bbe04.zip | |
wasm: hook up dot count to html input
Diffstat (limited to 'src/state.rs')
| -rw-r--r-- | src/state.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/state.rs b/src/state.rs index 592f26e..1793388 100644 --- a/src/state.rs +++ b/src/state.rs @@ -11,7 +11,6 @@ use crate::point::Point; pub const TAU: f64 = PI * 2.0; pub const MAX_SPEED: f64 = 0.01; -const NUM_POINTS: usize = 40; const VELVEC_SCALE: f64 = 3.0; #[derive(Debug)] @@ -33,15 +32,11 @@ impl State { .dyn_into()?; ctx.scale(canvas.width().into(), canvas.height().into())?; - let points = (0..NUM_POINTS) - .map(|_| Point::new(fastrand::f64(), fastrand::f64())) - .collect(); - Ok(Self { canvas, ctx, fps, - points, + points: vec![], last_time: None, inter_count: 1, }) @@ -104,6 +99,12 @@ impl State { Ok(()) } + pub fn set_dot_count(&mut self, n: usize) { + self.points = (0..n) + .map(|_| Point::new(fastrand::f64(), fastrand::f64())) + .collect(); + } + fn render_points(&self) -> JSResult<()> { for p in &self.points { self.ctx.set_fill_style_str(&p.color); |
