Implement camera colors
Still needs some unit tests, and to fix the gasket example
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use anyhow::{Context, Result};
|
||||
use enkou_shaders::Coefficients2;
|
||||
use enkou_shaders::camera::Camera;
|
||||
use enkou_shaders::camera::entry::main_camera;
|
||||
use enkou_shaders::camera::entry::main_image_render;
|
||||
use enkou_shaders::chaos_game::entry::main_chaos_game;
|
||||
use enkou_shaders::transform::Transform;
|
||||
use enkou_shaders::variation::Variation;
|
||||
use glam::{Affine2, IVec2, UVec2, Vec2, Vec4, uvec2, vec2};
|
||||
use image::{GrayImage, Luma};
|
||||
use glam::{Affine2, UVec2, Vec2, Vec4, uvec2, vec2};
|
||||
use image::{Rgba, Rgba32FImage};
|
||||
use std::mem;
|
||||
use std::process::Command;
|
||||
use tempfile::NamedTempFile;
|
||||
@@ -62,20 +62,26 @@ pub fn main() -> Result<()> {
|
||||
IMAGE_DIMENSION.as_vec2(),
|
||||
);
|
||||
|
||||
let palette = &[Vec4::ONE; 2];
|
||||
|
||||
let mut output_points_pixel = Vec::new();
|
||||
output_points_pixel.resize(ITERATIONS as usize, IVec2::ZERO);
|
||||
output_points_pixel.resize(ITERATIONS as usize, Vec4::ZERO);
|
||||
|
||||
main_camera(&camera, &output_points_ifs, &mut output_points_pixel);
|
||||
main_image_render(
|
||||
&camera,
|
||||
palette,
|
||||
&output_points_ifs,
|
||||
&mut output_points_pixel,
|
||||
);
|
||||
|
||||
let mut image = GrayImage::new(IMAGE_DIMENSION.x, IMAGE_DIMENSION.y);
|
||||
let dimensions = image.dimensions();
|
||||
output_points_pixel
|
||||
.iter()
|
||||
.skip_while(|p| {
|
||||
p.x < 0 || (p.x as u32) > dimensions.0 || p.y < 0 || (p.y as u32) > dimensions.1
|
||||
})
|
||||
.map(|p| (p.x as u32, p.y as u32))
|
||||
.for_each(|(x, y)| image.put_pixel(x, y, Luma([255u8])));
|
||||
let mut image = Rgba32FImage::new(IMAGE_DIMENSION.x, IMAGE_DIMENSION.y);
|
||||
for x in 0..image.dimensions().0 {
|
||||
for y in 0..image.dimensions().1 {
|
||||
let pixel_index = y * IMAGE_DIMENSION.x + x;
|
||||
let pixel = output_points_pixel[pixel_index as usize];
|
||||
image.put_pixel(x, y, Rgba(pixel.into()));
|
||||
}
|
||||
}
|
||||
|
||||
let temp = NamedTempFile::with_suffix(".png").context("Unable to create file for image")?;
|
||||
image.save(temp.path()).context("Unable to save image")?;
|
||||
|
||||
Reference in New Issue
Block a user