Punch direction vector
Draw punch vector ontop of circles (for better visibility)
This commit is contained in:
parent
7dc727104e
commit
505135b4d5
31
src/app.rs
31
src/app.rs
@ -91,7 +91,6 @@ impl eframe::App for Simulation {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
// The central panel the region left after adding TopPanel's and SidePanel's
|
||||
|
||||
// Simulatiom
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Click on circles or press");
|
||||
|
||||
@ -114,6 +113,15 @@ impl eframe::App for Simulation {
|
||||
|
||||
let painter = ui.painter();
|
||||
|
||||
for i in 0..min(self.circles.len(), self.colors.len()) {
|
||||
painter.circle(
|
||||
self.circles[i].c,
|
||||
self.circles[i].r,
|
||||
self.colors[i] /*Color32::TRANSPARENT*/,
|
||||
Stroke{width: 2.0, color: Color32::from_rgb(100, 200, 200)}
|
||||
);
|
||||
}
|
||||
|
||||
let (hover_pos, any_down, any_released) = ctx.input(|input| (
|
||||
input.pointer.hover_pos(),
|
||||
input.pointer.any_down(),
|
||||
@ -121,14 +129,13 @@ impl eframe::App for Simulation {
|
||||
));
|
||||
|
||||
if let Some(mousepos) = hover_pos {
|
||||
|
||||
self.circles.iter_mut().for_each(|circle|{
|
||||
let d = circle.c - mousepos;
|
||||
if d.length() < circle.r {
|
||||
if any_down {
|
||||
painter.line_segment(
|
||||
[circle.c, circle.c +d],
|
||||
Stroke{width: 3.0, color: Color32::from_rgb(255, 0, 0)});
|
||||
Stroke{width: 1.5, color: Color32::from_rgb(255, 0, 0)});
|
||||
}
|
||||
|
||||
if any_released {
|
||||
@ -138,20 +145,8 @@ impl eframe::App for Simulation {
|
||||
});
|
||||
}
|
||||
|
||||
for i in 0..min(self.circles.len(), self.colors.len()) {
|
||||
painter.circle(
|
||||
self.circles[i].c,
|
||||
self.circles[i].r,
|
||||
self.colors[i] /*Color32::TRANSPARENT*/,
|
||||
Stroke{width: 2.0, color: Color32::from_rgb(200, 255, 255)}
|
||||
);
|
||||
}
|
||||
// End simultion
|
||||
|
||||
ui.separator();
|
||||
|
||||
|
||||
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
|
||||
powered_by_egui_and_eframe(ui);
|
||||
egui::warn_if_debug_build(ui);
|
||||
@ -167,9 +162,9 @@ impl eframe::App for Simulation {
|
||||
self.circles.push(Circle::new(&ctx.used_rect()));
|
||||
self.colors.push(
|
||||
egui::Color32::from_rgba_premultiplied(
|
||||
rand::thread_rng().gen_range(64..255),
|
||||
rand::thread_rng().gen_range(64..255),
|
||||
rand::thread_rng().gen_range(64..255),
|
||||
rand::thread_rng().gen_range(0..255),
|
||||
rand::thread_rng().gen_range(0..255),
|
||||
rand::thread_rng().gen_range(0..255),
|
||||
128)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user