Browse Source

refined random extent generation

main
Thomas Johnson 11 months ago
parent
commit
043e7b65b0
  1. 4
      src/main.rs
  2. 24
      src/map.rs

4
src/main.rs

@ -27,10 +27,10 @@ fn main() {
initial_size: 50,
};
let map = cfg.create_map(&mut rng, 50);
for i in 0..75 {
for i in 0..50 {
map.apply_add(&image_in, &mut image_out, dims);
if i % 25 == 0 {
if true || i % 25 == 0 {
// write intermediate to file
let mut image_out_file = image_out.clone();
correct_image_brightness(&mut image_out_file, dims, 0.5, 1.0);

24
src/map.rs

@ -4,7 +4,7 @@ use rand::{Rng, distributions::{Uniform, WeightedIndex}};
use rand_distr::{Distribution};
use image::{Rgb, GenericImage};
#[derive(Debug)]
#[derive(Clone, Debug)]
pub struct Map
{
transforms: Vec<Transform>,
@ -41,7 +41,19 @@ impl Genetic for Map
cfg.create_map(rng, cfg.initial_size)
}
fn mutate<R: Rng>(&self, _rng: &mut R, _cfg: &Self::Configuration) -> Self {
fn mutate<R: Rng>(&self, mut rng: &mut R, _cfg: &Self::Configuration) -> Self {
match WeightedIndex::new(&[1, 1, 1, 1]).unwrap().sample(&mut rng) {
// four options are:
// - change a matrix
// - add element(s)
// - remove element(s)
// - change extents
0 => {
let which = rng.gen_range(0..self.transforms.len());
let mut new_tfs = self.transforms.clone();
},
_ => unimplemented!()
}
unimplemented!()
}
@ -67,7 +79,9 @@ impl MapGeneticConfig {
pub fn random_transform<R: Rng>(&self, mut rng: &mut R, c: f32) -> Transform {
let rect_xs = loop {
let pair = (rng.gen_range(0..self.dims.0), rng.gen_range(0..self.dims.0));
let first = rng.gen_range(0..self.dims.0);
let second = first as i32 + rng.gen_range(-(self.dims.0 as i32)..=self.dims.0 as i32);
let pair = (first, if second < 0 { 0 } else if second >= self.dims.0 as i32 { self.dims.0 - 1 } else { second as u32 });
if pair.1 < pair.0 {
break (pair.1, pair.0);
} else if pair.0 < pair.1 {
@ -75,7 +89,9 @@ impl MapGeneticConfig {
}
};
let rect_ys = loop {
let pair = (rng.gen_range(0..self.dims.1), rng.gen_range(0..self.dims.1));
let first = rng.gen_range(0..self.dims.1);
let second = first as i32 + rng.gen_range(-(self.dims.1 as i32)..=self.dims.1 as i32);
let pair = (first, if second < 0 { 0 } else if second >= self.dims.1 as i32 { self.dims.1 - 1 } else { second as u32 });
if pair.1 < pair.0 {
break (pair.1, pair.0);
} else if pair.0 < pair.1 {

Loading…
Cancel
Save