Skip to content
Snippets Groups Projects
Commit 1e61685f authored by Finn Bear's avatar Finn Bear
Browse files

Improvements and reorganization.

parent ffa12275
No related branches found
No related tags found
No related merge requests found
...@@ -3,10 +3,11 @@ use crate::slide::s1_title::Title; ...@@ -3,10 +3,11 @@ use crate::slide::s1_title::Title;
use crate::slide::s2_introduction::Introduction; use crate::slide::s2_introduction::Introduction;
use crate::slide::s3_complexity::Complexity; use crate::slide::s3_complexity::Complexity;
use crate::slide::s4_automata::Automata; use crate::slide::s4_automata::Automata;
use crate::slide::s5_fractals::Fractals; use crate::slide::s5_emergence::Emergence;
use crate::slide::s6_computation::Computation; use crate::slide::s6_fractals::Fractals;
use crate::slide::s7_mosaic::Mosaic; use crate::slide::s7_computation::Computation;
use crate::slide::s8_conclusion::Conclusion; use crate::slide::s8_mosaic::Mosaic;
use crate::slide::s9_conclusion::Conclusion;
use crate::slide::Slide; use crate::slide::Slide;
use eframe::egui::style::Margin; use eframe::egui::style::Margin;
use eframe::egui::{Key, Style, TextStyle, Visuals}; use eframe::egui::{Key, Style, TextStyle, Visuals};
...@@ -58,6 +59,7 @@ fn create_slides() -> Vec<Box<dyn Slide>> { ...@@ -58,6 +59,7 @@ fn create_slides() -> Vec<Box<dyn Slide>> {
Box::new(Introduction::default()), Box::new(Introduction::default()),
Box::new(Complexity::default()), Box::new(Complexity::default()),
Box::new(Automata::default()), Box::new(Automata::default()),
Box::new(Emergence::default()),
Box::new(Fractals::default()), Box::new(Fractals::default()),
Box::new(Computation::default()), Box::new(Computation::default()),
Box::new(Mosaic::default()), Box::new(Mosaic::default()),
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
pub mod arrow; pub mod arrow;
pub mod code; pub mod code;
pub mod example_list;
pub mod grid; pub mod grid;
pub mod image; pub mod image;
pub mod triangle; pub mod triangle;
use crate::component::image::Image; use crate::component::image::Image;
use crate::ctx_img;
use crate::egui::{Context, Frame, Ui}; use crate::egui::{Context, Frame, Ui};
use crate::fade_in::{fade_in, fade_in_manual}; use crate::fade_in::{fade_in, fade_in_manual};
use crate::slide::Slide;
use eframe::egui::style::Margin; use eframe::egui::style::Margin;
use eframe::egui::{Pos2, TextureHandle}; use eframe::egui::{Pos2, TextureHandle};
#[derive(Default)] #[derive(Default)]
pub struct Computation { pub struct ExampleList {
/// Will fade in one by one. /// Heading text.
examples: Vec<ComputationExample>, title: &'static str,
/// Examples to show.
examples: Vec<Example>,
} }
/// One bullet point and texture combination. /// One bullet point and texture combination.
struct ComputationExample { pub struct Example {
/// Bullet point text. /// Bullet point text.
label: &'static str, label: &'static str,
/// Texture handle to render on the right side. /// Texture handle to render on the right side.
...@@ -22,7 +22,7 @@ struct ComputationExample { ...@@ -22,7 +22,7 @@ struct ComputationExample {
fade_start: Option<f64>, fade_start: Option<f64>,
} }
impl ComputationExample { impl Example {
pub fn new(label: &'static str, texture: TextureHandle) -> Self { pub fn new(label: &'static str, texture: TextureHandle) -> Self {
Self { Self {
label, label,
...@@ -32,8 +32,15 @@ impl ComputationExample { ...@@ -32,8 +32,15 @@ impl ComputationExample {
} }
} }
impl Slide for Computation { impl ExampleList {
fn transition(&mut self, ctx: &Context) -> bool { pub fn new(title: &'static str) -> Self {
Self {
title,
examples: Vec::new(),
}
}
pub fn transition(&mut self, ctx: &Context) -> bool {
for example in &mut self.examples { for example in &mut self.examples {
if example.fade_start.is_none() { if example.fade_start.is_none() {
// If any image has not yet started fading in, fade it in and don't go to next slide. // If any image has not yet started fading in, fade it in and don't go to next slide.
...@@ -44,24 +51,20 @@ impl Slide for Computation { ...@@ -44,24 +51,20 @@ impl Slide for Computation {
true true
} }
fn show(&mut self, ui: &mut Ui) { /// Will call setter function once to populate examples.
pub fn show(&mut self, ui: &mut Ui, setter: impl FnOnce() -> Vec<Example>) {
if self.examples.is_empty() { if self.examples.is_empty() {
// For now, these images are somewhat like placeholders. self.examples = setter();
self.examples = vec![
ComputationExample::new("Raytracing", ctx_img!(ui.ctx(), "raytracing0.png")),
ComputationExample::new("Raymarching", ctx_img!(ui.ctx(), "raymarching1.png")),
ComputationExample::new("Particle simulation", ctx_img!(ui.ctx(), "atom0.png")),
ComputationExample::new("Fluid simulation", ctx_img!(ui.ctx(), "fluid0.png")),
]
} }
const IMAGE_SCALE: f32 = 256.0; const IMAGE_SCALE: f32 = 256.0;
let window_width = ui.available_width(); let window_width = ui.available_width();
let window_height = ui.available_height(); let window_height = ui.available_height();
let window_width_per_image = window_width / self.examples.len() as f32; let window_width_per_image = window_width / self.examples.len() as f32;
let aspect_ratio_gap = (window_width_per_image - IMAGE_SCALE) * 0.5;
Frame::none().margin(Margin::same(20.0)).show(ui, |ui| { Frame::none().margin(Margin::same(20.0)).show(ui, |ui| {
ui.heading("More Computation-based Art"); ui.heading(self.title);
ui.add_space(8.0); ui.add_space(8.0);
for (i, example) in self.examples.iter().enumerate() { for (i, example) in self.examples.iter().enumerate() {
if let Some(fade_start) = example.fade_start { if let Some(fade_start) = example.fade_start {
...@@ -70,9 +73,9 @@ impl Slide for Computation { ...@@ -70,9 +73,9 @@ impl Slide for Computation {
}); });
fade_in_manual(ui, fade_start, |ui, alpha| { fade_in_manual(ui, fade_start, |ui, alpha| {
let position = Pos2::new( let position = Pos2::new(
(window_width_per_image - IMAGE_SCALE) * 0.5 aspect_ratio_gap
+ window_width * (i as f32) / self.examples.len() as f32, + window_width * (i as f32) / self.examples.len() as f32,
window_height - IMAGE_SCALE * 1.1, window_height - IMAGE_SCALE - aspect_ratio_gap,
); );
Image::default() Image::default()
.height(IMAGE_SCALE) .height(IMAGE_SCALE)
......
src/image/placeholder0.png

5.74 KiB

src/image/placeholder1.png

5.74 KiB

...@@ -6,10 +6,11 @@ pub mod s1_title; ...@@ -6,10 +6,11 @@ pub mod s1_title;
pub mod s2_introduction; pub mod s2_introduction;
pub mod s3_complexity; pub mod s3_complexity;
pub mod s4_automata; pub mod s4_automata;
pub mod s5_fractals; pub mod s5_emergence;
pub mod s6_computation; pub mod s6_fractals;
pub mod s7_mosaic; pub mod s7_computation;
pub mod s8_conclusion; pub mod s8_mosaic;
pub mod s9_conclusion;
/// An interface for all slides. /// An interface for all slides.
pub trait Slide { pub trait Slide {
......
use crate::component::example_list::{Example, ExampleList};
use crate::ctx_img;
use crate::egui::{Context, Ui};
use crate::slide::Slide;
pub struct Emergence {
inner: ExampleList,
}
impl Default for Emergence {
fn default() -> Self {
Self {
inner: ExampleList::new("More Emergence-based Art"),
}
}
}
impl Slide for Emergence {
fn transition(&mut self, ctx: &Context) -> bool {
self.inner.transition(ctx)
}
fn show(&mut self, ui: &mut Ui) {
let ctx = ui.ctx().clone();
self.inner.show(ui, || {
vec![
Example::new("Langton's ant", ctx_img!(ctx, "placeholder0.png")),
Example::new("Flocking simulation", ctx_img!(ctx, "placeholder1.png")),
Example::new("Slime mold simulation", ctx_img!(ctx, "slime0.png")),
]
});
}
}
...@@ -10,9 +10,9 @@ use crate::egui::{Color32, Context, Frame, Ui}; ...@@ -10,9 +10,9 @@ use crate::egui::{Color32, Context, Frame, Ui};
use crate::fade_in::{fade_in_manual, fade_out_manual}; use crate::fade_in::{fade_in_manual, fade_out_manual};
use crate::governor::Governor; use crate::governor::Governor;
use crate::slide::s4_automata::randomize_grid; use crate::slide::s4_automata::randomize_grid;
use crate::slide::s5_fractals::circle::circle; use crate::slide::s6_fractals::circle::circle;
use crate::slide::s5_fractals::mandelbrot::mandelbrot; use crate::slide::s6_fractals::mandelbrot::mandelbrot;
use crate::slide::s5_fractals::rectangle::rectangle; use crate::slide::s6_fractals::rectangle::rectangle;
use crate::slide::Slide; use crate::slide::Slide;
use eframe::egui::style::Margin; use eframe::egui::style::Margin;
use eframe::egui::{Align2, Vec2}; use eframe::egui::{Align2, Vec2};
...@@ -172,17 +172,17 @@ impl Slide for Fractals { ...@@ -172,17 +172,17 @@ impl Slide for Fractals {
// No-op (arrows are rendered below). // No-op (arrows are rendered below).
} }
FractalsState::Rectangle { pixels } => { FractalsState::Rectangle { pixels } => {
self.code.code = pseudocode(include_str!("s5_fractals/rectangle.rs")); self.code.code = pseudocode(include_str!("s6_fractals/rectangle.rs"));
algo = Some(&rectangle); algo = Some(&rectangle);
limit_pixels = Some(pixels) limit_pixels = Some(pixels)
} }
FractalsState::Circle { pixels } => { FractalsState::Circle { pixels } => {
self.code.code = pseudocode(include_str!("s5_fractals/circle.rs")); self.code.code = pseudocode(include_str!("s6_fractals/circle.rs"));
algo = Some(&circle); algo = Some(&circle);
limit_pixels = Some(pixels); limit_pixels = Some(pixels);
} }
FractalsState::Mandelbrot { pixels } => { FractalsState::Mandelbrot { pixels } => {
self.code.code = pseudocode(include_str!("s5_fractals/mandelbrot.rs")); self.code.code = pseudocode(include_str!("s6_fractals/mandelbrot.rs"));
algo = Some(&mandelbrot); algo = Some(&mandelbrot);
limit_pixels = Some(pixels); limit_pixels = Some(pixels);
} }
......
File moved
File moved
use crate::component::example_list::{Example, ExampleList};
use crate::ctx_img;
use crate::egui::{Context, Ui};
use crate::slide::Slide;
pub struct Computation {
inner: ExampleList,
}
impl Default for Computation {
fn default() -> Self {
Self {
inner: ExampleList::new("More Computation-based Art"),
}
}
}
impl Slide for Computation {
fn transition(&mut self, ctx: &Context) -> bool {
self.inner.transition(ctx)
}
fn show(&mut self, ui: &mut Ui) {
let ctx = ui.ctx().clone();
self.inner.show(ui, || {
vec![
Example::new("Raytracing", ctx_img!(ctx, "raytracing0.png")),
Example::new("Raymarching", ctx_img!(ctx, "raymarching1.png")),
Example::new("Particle simulation", ctx_img!(ctx, "atom0.png")),
Example::new("Fluid simulation", ctx_img!(ctx, "fluid0.png")),
]
});
}
}
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment