Browse Source

moved magic heuristic coefficient

main
Thomas Johnson 12 months ago
parent
commit
f9755ebf87
  1. 9
      src/map.rs
  2. 4
      src/transform.rs

9
src/map.rs

@ -12,9 +12,10 @@ pub struct Map
impl Map {
pub fn apply_add<I: GenericImage<Pixel=Rgb<f32>>, O: GenericImage<Pixel=Rgb<f32>>>(&self, input: &I, output: &mut O, dims: (u32, u32)) {
let offset = 1.0;//((dims.0 * dims.1 * NCOLORS as u32) as f32).sqrt().recip();
let offset = 1.0;
let c = (self.transforms.len() as f32).sqrt().recip() * 3.5;
for tf in self.transforms.iter() {
tf.apply_add(input, output, dims);
tf.apply_add(input, output, dims, c);
}
for x in 0..dims.0 {
for y in 0..dims.1 {
@ -57,7 +58,7 @@ impl MapGeneticConfig {
pub fn create_map<R: Rng>(&self, rng: &mut R, tf_count: usize) -> Map {
let mut transforms = vec![];
for _ in 0..tf_count {
transforms.push(self.random_transform(rng, (tf_count as f32).recip().sqrt() * 3.5));
transforms.push(self.random_transform(rng, 1.0));
}
Map {
transforms,
@ -92,7 +93,7 @@ impl MapGeneticConfig {
3 => ((cx + e2x, cy + e2y), [(-e2x, -e2y), (e1x, e1y)]),
_ => unreachable!(),
};
let color_matrix_bound = /*((self.dims.0 * self.dims.1 * NCOLORS as u32) as f32).sqrt().recip() * */c;
let color_matrix_bound = c;
let mut matrix_coeff_dist = Uniform::new(-color_matrix_bound, color_matrix_bound).sample_iter(rng);
let mut color_matrix = [0.0f32; NCOLORS * NCOLORS];
for i in 0..NCOLORS * NCOLORS {

4
src/transform.rs

@ -13,7 +13,7 @@ pub struct Transform {
}
impl Transform {
pub fn apply_add<I: GenericImage<Pixel=Rgb<f32>>, O: GenericImage<Pixel=Rgb<f32>>>(&self, input: &I, output: &mut O, dims: (u32, u32)) {
pub fn apply_add<I: GenericImage<Pixel=Rgb<f32>>, O: GenericImage<Pixel=Rgb<f32>>>(&self, input: &I, output: &mut O, dims: (u32, u32), c: f32) {
for x_off in 0..self.from_extents.0 {
let x = x_off as f32 / self.from_extents.0 as f32;
for y_off in 0..self.from_extents.1 {
@ -52,7 +52,7 @@ impl Transform {
let y_out = self.from_corner.1 + y_off;
let mut pix = output.get_pixel(x_out, y_out).0;
for i in 0..NCOLORS {
pix[i] += color[i];
pix[i] += color[i] * c;
}
output.put_pixel(x_out, y_out, Rgb(pix));
}

Loading…
Cancel
Save