2025-07-10 15:00:26 -04:00
|
|
|
use blob_guy::blob_guy::Blob;
|
|
|
|
|
use blob_guy::chunk::{Chunks, Pos};
|
2025-07-01 12:26:35 -04:00
|
|
|
use eframe::egui;
|
2025-07-01 15:39:51 -04:00
|
|
|
use rupl::types::{Color, Graph, GraphType, Name, Show, Vec2};
|
2025-07-01 12:26:35 -04:00
|
|
|
fn main() {
|
|
|
|
|
eframe::run_native(
|
|
|
|
|
"blob",
|
|
|
|
|
eframe::NativeOptions {
|
|
|
|
|
..Default::default()
|
|
|
|
|
},
|
|
|
|
|
Box::new(|_| Ok(Box::new(App::new()))),
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
|
|
|
|
}
|
|
|
|
|
impl eframe::App for App {
|
|
|
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
|
|
|
self.main(ctx);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct App {
|
|
|
|
|
plot: Graph,
|
|
|
|
|
data: Data,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Data {
|
|
|
|
|
blob: Blob,
|
2025-07-10 15:00:26 -04:00
|
|
|
world: Chunks,
|
2025-07-01 12:26:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Data {
|
|
|
|
|
fn new() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
blob: Blob::new(0.0, 0.0),
|
2025-07-10 15:00:26 -04:00
|
|
|
world: Default::default(),
|
2025-07-01 12:26:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn update(&mut self, plot: &mut Graph) {
|
|
|
|
|
let s = &plot.names[0].vars[0];
|
|
|
|
|
let s = &s[3..s.len() - 1];
|
|
|
|
|
let (a, b) = s.split_once(',').unwrap();
|
|
|
|
|
let GraphType::Point(p) = &mut plot.data[0] else {
|
|
|
|
|
unreachable!()
|
|
|
|
|
};
|
|
|
|
|
p.x = a.parse().unwrap();
|
|
|
|
|
p.y = b.parse().unwrap();
|
|
|
|
|
self.blob.pos = Pos::new(p.x as f32, p.y as f32);
|
2025-07-10 15:00:26 -04:00
|
|
|
self.blob
|
|
|
|
|
.update(self.blob.pos.to_chunk(), &mut self.world)
|
|
|
|
|
.unwrap();
|
2025-07-01 12:26:35 -04:00
|
|
|
plot.data.drain(1..);
|
2025-07-01 15:39:51 -04:00
|
|
|
plot.main_colors.drain(1..);
|
2025-07-01 13:10:44 -04:00
|
|
|
for ((_x, _y), _p) in self.blob.pixels.iter() {
|
|
|
|
|
let p1 = Vec2::new(*_x as f64 + 0.5, *_y as f64 + 0.5);
|
|
|
|
|
//let p2 = Vec2::new(_p.pos.x as f64, _p.pos.y as f64);
|
|
|
|
|
plot.data.push(GraphType::Point(p1));
|
2025-07-01 15:39:51 -04:00
|
|
|
plot.main_colors.push(Color {
|
|
|
|
|
r: 170,
|
|
|
|
|
g: 170,
|
|
|
|
|
b: 255,
|
|
|
|
|
});
|
|
|
|
|
/*plot.data.push(GraphType::Point(p2));
|
|
|
|
|
plot.main_colors.push(Color {
|
|
|
|
|
r: 170,
|
|
|
|
|
g: 255,
|
|
|
|
|
b: 170,
|
|
|
|
|
})*/
|
2025-07-01 12:26:35 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
impl App {
|
|
|
|
|
fn new() -> Self {
|
|
|
|
|
let mut plot = Graph::new(
|
|
|
|
|
vec![GraphType::Point(Vec2::splat(0.0))],
|
|
|
|
|
vec![Name {
|
|
|
|
|
vars: vec!["a={0,0}".to_string()],
|
|
|
|
|
name: "a".to_string(),
|
|
|
|
|
show: Show::Real,
|
|
|
|
|
}],
|
|
|
|
|
false,
|
2025-07-01 15:39:51 -04:00
|
|
|
-32.0,
|
|
|
|
|
32.0,
|
2025-07-01 12:26:35 -04:00
|
|
|
);
|
|
|
|
|
plot.point_size = 8.0;
|
|
|
|
|
App {
|
|
|
|
|
plot,
|
|
|
|
|
data: Data::new(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fn main(&mut self, ctx: &egui::Context) {
|
|
|
|
|
egui::CentralPanel::default()
|
|
|
|
|
.frame(egui::Frame::default().fill(egui::Color32::from_rgb(255, 255, 255)))
|
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
|
self.plot.keybinds(ui);
|
|
|
|
|
let rect = ctx.available_rect();
|
|
|
|
|
self.plot
|
|
|
|
|
.set_screen(rect.width() as f64, rect.height() as f64, true, true);
|
|
|
|
|
self.data.update(&mut self.plot);
|
|
|
|
|
self.plot.update(ctx, ui);
|
|
|
|
|
ctx.request_repaint();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|