Lenia: replace kernel with one from the paper, replace glider with a new life form
This commit is contained in:
parent
481a12ecee
commit
05e0789077
9 changed files with 71 additions and 73 deletions
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.4 KiB |
|
@ -8,9 +8,7 @@ fn main() {
|
|||
return;
|
||||
}
|
||||
let radius = args[0].parse().unwrap();
|
||||
let k_offset = 0.435;
|
||||
let k_sharpness = 28.0;
|
||||
let precision = 50.0; // for rounding
|
||||
let precision = 100.0; // for rounding
|
||||
|
||||
let mut img = image::RgbImage::new(radius * 2 + 1, radius * 2 + 1);
|
||||
|
||||
|
@ -18,11 +16,11 @@ fn main() {
|
|||
let mut total_lookups = 0;
|
||||
println!("// generated by the rust program");
|
||||
println!("#define RADIUS {}", radius);
|
||||
println!("const half Kernel[{}][{}] = {{", radius + 1, radius);
|
||||
println!("const float Kernel[{}][{}] = {{", radius + 1, radius);
|
||||
for y in 0..=radius {
|
||||
print!(" {{");
|
||||
for x in 1..=radius {
|
||||
let k = (k(x, y, radius, k_offset, k_sharpness) * precision).floor() / precision;
|
||||
let k = (k(x, y, radius) * precision).floor() / precision;
|
||||
total_max += k * 4.0;
|
||||
if k > 0.0 {
|
||||
total_lookups += 1;
|
||||
|
@ -50,15 +48,18 @@ fn main() {
|
|||
img.save("kernel.png").unwrap();
|
||||
}
|
||||
|
||||
fn k(x: u32, y: u32, radius: u32, k_offset: f32, k_sharpness: f32) -> f32 {
|
||||
fn k(x: u32, y: u32, radius: u32) -> f32 {
|
||||
let x = x as f32;
|
||||
let y = y as f32;
|
||||
let r = (x * x + y * y).sqrt() / radius as f32;
|
||||
f32::exp(-((r - k_offset) * (r - k_offset)) * k_sharpness)
|
||||
// let k_offset = 0.435;
|
||||
// let k_sharpness = 28.0;
|
||||
// f32::exp(-((r - k_offset) * (r - k_offset)) * k_sharpness)
|
||||
|
||||
// lenia paper example kernel
|
||||
// if r < 1.0 {
|
||||
// f32::exp(4.0 - 4.0 / (4.0 * r * (1.0 - r)))
|
||||
// } else {
|
||||
// 0.0
|
||||
// }
|
||||
if r < 1.0 {
|
||||
f32::exp(4.0 - 4.0 / (4.0 * r * (1.0 - r)))
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue