Anonymous user
Brownian tree: Difference between revisions
→{{header|Rust}}: Update library to rand = "^0.8"
m (→{{header|Phix}}: IupCloseOnEscape no longer needed) |
(→{{header|Rust}}: Update library to rand = "^0.8") |
||
Line 4,126:
use image::ColorType;
use std::cmp::{min, max};
use std::env;
use std::path::Path;
use std::process;
use rand::Rng;
fn help() {
Line 4,172 ⟶ 4,173:
width as u32,
height as u32,
ColorType::
Err(e) => println!("Error writing output image:\n{}", e),
Ok(_) => println!("Output written to:\n{}", output_path.to_str().unwrap()),
Line 4,183 ⟶ 4,184:
let mut field_base: Vec<_> = raw.as_mut_slice().chunks_mut(width).collect();
// Addressable 2d vector
let
// Seed mote
field[width / 2][height / 2] = 1;
let x_spawn_range = Range::new(1usize, width - 1);▼
let mut rng = rand::thread_rng();
Line 4,198 ⟶ 4,196:
}
let mut
// Increment field value when motes spawn on top of the structure
Line 4,210 ⟶ 4,207:
loop {
let contacts = field[x - 1][y - 1] + field[x][y - 1] + field[x + 1][y - 1] +
if contacts > 0 {
Line 4,218 ⟶ 4,215:
break;
} else {
let xw =
let yw =
if xw < 1 || xw >= (width as i32 - 1) || yw < 1 || yw >= (height as i32 - 1) {
break;
Line 4,229 ⟶ 4,226:
}
}</lang>
For a 512 x 512 field and
<center>[[File:Rust-Brownian-512-20k.png]]</center>
|