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

Conway WIP.

parent e30c69b1
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ pub mod slide;
use crate::slide::s1_title::Title;
use crate::slide::s2_introduction::Introduction;
use crate::slide::s3_complexity::Complexity;
use crate::slide::s4_conway::Conway;
use crate::slide::Slide;
use eframe::egui::style::{Margin, Widgets};
use eframe::egui::{
......@@ -56,6 +57,7 @@ fn create_slides() -> Vec<Box<dyn Slide>> {
Box::new(Title::default()) as Box<dyn Slide>,
Box::new(Introduction::default()),
Box::new(Complexity::default()),
Box::new(Conway::default()),
]
}
......@@ -119,7 +121,9 @@ impl epi::App for Cartoon {
}
} else {
ctx.request_repaint();
self.slide_index.saturating_sub(1)
self.slide_index
.checked_sub(1)
.unwrap_or(self.slides.len() - 1)
};
}
......
......@@ -4,6 +4,7 @@ use eframe::{egui, epi};
pub mod s1_title;
pub mod s2_introduction;
pub mod s3_complexity;
pub mod s4_conway;
pub trait Slide {
fn show(&mut self, ui: &mut Ui, ctx: &Context);
......
use crate::Slide;
use eframe::egui::{
Align2, Color32, Context, Frame, Grid, Pos2, Rect, Shape, Stroke, Ui, Vec2, Window,
};
use eframe::emath;
#[derive(Default)]
pub struct Conway {}
impl Slide for Conway {
fn show(&mut self, ui: &mut Ui, ctx: &Context) {
let PIXELS: f32 = 400.0;
let CELLS: usize = 32;
Window::new("conway")
.title_bar(false)
//.frame(Frame::none())
.anchor(Align2::CENTER_CENTER, Vec2::ZERO)
.fixed_size(Vec2::splat(PIXELS))
.show(ctx, |ui| {
let (_id, rect) = ui.allocate_space(Vec2::splat(PIXELS));
let to_screen = emath::RectTransform::from_to(
Rect::from_x_y_ranges(0.0..=1.0, 0.0..=1.0),
rect,
);
for c in 0..=CELLS {
let coord = c as f32 / CELLS as f32;
// Horizontal.
ui.painter().add(Shape::LineSegment {
points: [
to_screen * Pos2::new(0.0, coord),
to_screen * Pos2::new(1.0, coord),
],
stroke: Stroke::new(1.0, Color32::BLACK),
});
// Vertical.
ui.painter().add(Shape::LineSegment {
points: [
to_screen * Pos2::new(coord, 0.0),
to_screen * Pos2::new(coord, 1.0),
],
stroke: Stroke::new(1.0, Color32::GRAY),
});
}
for x in 0..=CELLS {
for y in 0..=CELLS {}
}
});
}
}
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