diff --git a/petri/src/lib.rs b/petri/src/lib.rs index a1ddf42..66521e1 100644 --- a/petri/src/lib.rs +++ b/petri/src/lib.rs @@ -20,7 +20,7 @@ pub struct Chunk { pub struct Rule { pub from: RulePattern, pub to: RulePattern, - pub enabled: bool, + // enabled: bool // probability: u8 // flip: // rotate: @@ -29,7 +29,6 @@ pub struct Rule { impl Rule { pub fn new() -> Self { Self { - enabled: false, from: RulePattern::new(), to: RulePattern::new(), } @@ -73,7 +72,6 @@ impl Dish { rules: vec![ Rule { - enabled: true, from: RulePattern { width: 1, height: 2, @@ -86,7 +84,6 @@ impl Dish { }, }, Rule { - enabled: true, from: RulePattern { width: 2, height: 2, @@ -99,7 +96,6 @@ impl Dish { }, }, Rule { - enabled: true, from: RulePattern { width: 2, height: 2, @@ -116,22 +112,10 @@ impl Dish { } pub fn fire_blindly(&mut self) { - if self.rules.is_empty() { - return; - } + assert!(!self.rules.is_empty()); let x = random::() % CHUNK_SIZE; let y = random::() % CHUNK_SIZE; - let enabled_rules = self - .rules - .iter() - .enumerate() - .filter_map(|(i, r)| r.enabled.then_some(i)) - .collect::>(); - if enabled_rules.is_empty() { - return; - } - let rule = random::() % enabled_rules.len(); - let rule = enabled_rules[rule]; + let rule = random::() % self.rules.len(); self.fire_rule(rule, x, y); } diff --git a/uscope/src/main.rs b/uscope/src/main.rs index 48e462f..a71cb9d 100644 --- a/uscope/src/main.rs +++ b/uscope/src/main.rs @@ -33,7 +33,7 @@ impl UScope { fn new(_cc: &eframe::CreationContext<'_>) -> Self { Self { dish: Dish::new(), - speed: 250, + speed: 100, brush: Cell(1), celltypes: vec![ CellData::new("air", 0, 0, 0), @@ -51,10 +51,7 @@ impl eframe::App for UScope { } SidePanel::left("left_panel").show(ctx, |ui| { ui.heading("Simulation"); - ui.label("speed"); ui.add(Slider::new(&mut self.speed, 0..=5000)); - ui.separator(); - ui.heading("Cells"); for (i, cell) in self.celltypes.iter_mut().enumerate() { ui.horizontal(|ui| { @@ -64,7 +61,6 @@ impl eframe::App for UScope { ui.color_edit_button_srgba(&mut cell.color); }); } - if ui.button("add cell").clicked() { let h = random::(); let s = random::() * 0.5 + 0.5; @@ -73,19 +69,9 @@ impl eframe::App for UScope { let name = format!("cell #{}", self.celltypes.len()); self.celltypes.push(CellData { name, color }) } - ui.separator(); - ui.heading("Rules"); - let mut to_remove = None; - for (i, rule) in self.dish.rules.iter_mut().enumerate() { + for rule in &mut self.dish.rules { rule_editor(ui, rule, &self.celltypes); - if ui.button("delete").clicked() { - to_remove = Some(i); - } - ui.separator(); - } - if let Some(i) = to_remove { - self.dish.rules.remove(i); } if ui.button("add rule").clicked() { self.dish.rules.push(Rule::new()); @@ -122,10 +108,8 @@ fn paint_chunk(painter: Painter, chunk: &Chunk, cells: &[CellData]) { } const CSIZE: f32 = 24.; -const OUTLINE: (f32, Color32) = (3., Color32::GRAY); +const OUTLINE: (f32, Color32) = (1., Color32::GRAY); fn rule_editor(ui: &mut Ui, rule: &mut Rule, cells: &[CellData]) { - ui.checkbox(&mut rule.enabled, "enable rule"); - let cells_y = rule.from.height(); let cells_x = rule.from.width(); let margin = 8.;