summaryrefslogtreecommitdiff
path: root/src/math.rs
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2019-07-02 10:17:19 -0500
committertom barrett <spalf0@gmail.com>2019-07-02 10:17:19 -0500
commit976ad40137cf468eda32b1d947c524bfaeeaa7da (patch)
treef27dfa9da31903b73e14a0572cf738b4b62dcf4b /src/math.rs
parent6bf9e96140c91340d6ae643b6e0896aa734d8605 (diff)
cargo updated
Diffstat (limited to 'src/math.rs')
-rw-r--r--src/math.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/math.rs b/src/math.rs
index c747cce..ff652ea 100644
--- a/src/math.rs
+++ b/src/math.rs
@@ -1,4 +1,6 @@
use ggez::graphics::Rect;
+use ggez::nalgebra::Point2;
+use rand::Rng;
use std::f32::consts::PI;
use std::time::Instant;
@@ -27,3 +29,9 @@ pub fn next_source(source: Rect, animation: &[(usize, Rect)], timer: Instant) ->
(source, timer)
}
}
+
+pub fn random_nearby_point(origin: Point2<f32>, within_radius: f32) -> Point2<f32> {
+ let w = within_radius * rand::thread_rng().gen_range(0.0, 1.0);
+ let t = 2.0 * PI * rand::thread_rng().gen_range(0.0, 1.0);
+ Point2::new(origin.x + w * t.cos(), origin.y + w * t.sin())
+}