mod colormap; mod colorramp; mod julia; use std::{ops::Add, path::Path}; use colormap::{ColormapInputImage, ColormapMappingImage, ColormapOutputImage, ColormapPlugin}; use colorramp::ColorRamp; use julia::{JuliaData, JuliaPlugin}; use bevy::{ diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, prelude::*, render::render_resource::*, window::{WindowDescriptor, WindowResized}, }; use csv; use palette::{rgb::Rgba, FromColor, Pixel}; use std::fs::File; use bevy_better_exit::{BetterExitPlugin, ExitEvent, ExitListener}; struct MovementPath(Vec); fn main() { App::new() .insert_resource(ClearColor(Color::BLACK)) .insert_resource(WindowDescriptor { ..Default::default() }) .add_plugins(DefaultPlugins) .add_plugin(JuliaPlugin) .add_plugin(ColormapPlugin::with_previous("julia")) .add_plugin(LogDiagnosticsPlugin::default()) .add_plugin(FrameTimeDiagnosticsPlugin::default()) .add_plugin(BetterExitPlugin::new(None)) .add_startup_system(setup) .add_startup_system(load_path) .add_system(modi) .add_system(window_size) .add_system(bevy_better_exit::exit_on_esc_system) //.add_system(update_color) .run(); } fn setup( mut commands: Commands, mut images: ResMut>, mut params: ResMut>, ) { let mut julia_image = Image::new_fill( Extent3d { width: 400, height: 400, depth_or_array_layers: 1, }, TextureDimension::D2, &(0.0 as f32).to_ne_bytes(), TextureFormat::R32Float, ); julia_image.texture_descriptor.usage = TextureUsages::COPY_DST | TextureUsages::STORAGE_BINDING | TextureUsages::TEXTURE_BINDING; let julia_image = images.add(julia_image); let mut mapped_image = Image::new_fill( Extent3d { width: 400, height: 400, depth_or_array_layers: 1, }, TextureDimension::D2, &[0, 0, 0, 255], TextureFormat::Rgba8Unorm, ); mapped_image.texture_descriptor.usage = TextureUsages::COPY_DST | TextureUsages::STORAGE_BINDING | TextureUsages::TEXTURE_BINDING; let mapped_image = images.add(mapped_image); let mut ramp = ColorRamp::new(); ramp.add(0.0, 0.0, 0.0, 0.0, 1.0); ramp.add(0.04, 0.0, 0.0, 0.0, 1.0); ramp.add(0.2, 0.4, 0.0, 0.0, 1.0); ramp.add(0.5, 1.0, 0.4, 0.0, 1.0); ramp.add(0.8, 1.0, 1.0, 0.0, 1.0); ramp.add(1.0, 1.0, 1.0, 1.0, 1.0); /*let mut ramp = ColorRamp::new(); ramp.add(0.00, 0.0, 0.0, 0.0, 1.0); ramp.add(0.02, 0.0, 0.0, 0.0, 1.0); ramp.add(0.05, 0.0, 0.0, 0.4, 1.0); ramp.add(0.1, 0.0, 0.3, 1.0, 1.0); ramp.add(0.15, 0.6, 0.6, 1.0, 1.0); ramp.add(0.2, 1.0, 1.0, 0.0, 1.0); ramp.add(0.3, 1.0, 0.4, 0.0, 1.0); ramp.add(0.4, 0.6, 0.0, 0.0, 1.0); ramp.add(1.0, 0.0, 0.0, 0.0, 1.0);*/ let data = ramp.build_texture_data(1024, 1).unwrap(); let mut mapping_image = Image::new_fill( Extent3d { width: 1024, height: 1, depth_or_array_layers: 1, }, TextureDimension::D1, &[128, 64, 0, 255], TextureFormat::Rgba8Unorm, ); mapping_image.data = data; mapping_image.texture_descriptor.usage = TextureUsages::COPY_DST | TextureUsages::STORAGE_BINDING | TextureUsages::TEXTURE_BINDING; let mapping_image = images.add(mapping_image); let data = JuliaData { c: Vec2::new(0.2, 0.3), view_aspect: 1.0, view_center: Vec2::new(0.0, 0.0), view_scale: 0.5, iters: 128, image: julia_image.clone(), }; let data = params.add(data); commands.spawn_bundle(SpriteBundle { texture: mapped_image.clone(), ..Default::default() }); commands.insert_resource(ColormapInputImage(julia_image)); commands.insert_resource(ColormapOutputImage(mapped_image)); commands.insert_resource(ColormapMappingImage(mapping_image)); commands.spawn_bundle(Camera2dBundle::default()); commands.insert_resource(data); } fn load_path(mut commands: Commands) { let mut reader = csv::ReaderBuilder::new() .has_headers(false) .from_reader(File::open("assets/path.csv").unwrap()); let mut points: Vec = Vec::new(); for r in reader.records() { let record = r.unwrap(); let data = record.deserialize::<[f32; 2]>(None).unwrap(); let x = data[0] / 2822.22217 * 4. - 2.5; let y = data[1] / 2822.22217 * 4. - 2.; points.push(Vec2::new(x, y)); } commands.insert_resource(MovementPath(points)); } fn modi( mut params: ResMut>, data: Res>, time: Res