MCPcopy Create free account
hub / github.com/algorithm-archivists/algorithm-archive / chaos_game

Function chaos_game

contents/IFS/code/rust/IFS.rs:9–20  ·  view source on GitHub ↗
(iters: usize, shapes: Vec<Point>)

Source from the content-addressed store, hash-verified

7}
8
9fn chaos_game(iters: usize, shapes: Vec<Point>) -> Vec<Point> {
10 let mut rng = rand::thread_rng();
11 let mut p = Point{x: rng.gen(), y: rng.gen()};
12
13 (0..iters).into_iter().map(|_| {
14 let old_point = p;
15 let tmp = shapes[rng.gen_range(0..shapes.len())];
16 p.x = 0.5 * (p.x + tmp.x);
17 p.y = 0.5 * (p.y + tmp.y);
18 old_point
19 }).collect()
20}
21
22fn main() {
23 let shapes = vec![

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected