mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 21:30:03 -04:00
Plot refactor (#331)
* drag and zoom support for plots * update doctest * use impl ToString * revert back to Into<String> until #302 is solved * Apply suggestions from code review Co-authored-by: ilya sheprut <optitel223@gmail.com> * use persistence feature for PlotMemory * * split plot into multiple files * add curve from function * move more functionality into ScreenTransform struct * changes from code review in base branch * let user specify a range for generated functions * rename file * minor changes * improve generator functionality * improve callback and add parametric callback * minor changes * add documentation * fix merge issues * changes based on review * rename folder * make plot.rs the mod.rs file * remove mod.rs * rename file * namespace changes * fix doctest * Update egui/src/widgets/plot/items.rs Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com> Co-authored-by: ilya sheprut <optitel223@gmail.com> Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b69bc2c06a
commit
a505d01090
@@ -6,7 +6,7 @@ use std::f64::consts::TAU;
|
||||
pub struct PlotDemo {
|
||||
animate: bool,
|
||||
time: f64,
|
||||
circle_radius: f32,
|
||||
circle_radius: f64,
|
||||
circle_center: Pos2,
|
||||
square: bool,
|
||||
proportional: bool,
|
||||
@@ -17,7 +17,7 @@ impl Default for PlotDemo {
|
||||
Self {
|
||||
animate: true,
|
||||
time: 0.0,
|
||||
circle_radius: 0.5,
|
||||
circle_radius: 1.5,
|
||||
circle_center: Pos2::new(0.0, 0.0),
|
||||
square: false,
|
||||
proportional: true,
|
||||
@@ -96,7 +96,7 @@ impl PlotDemo {
|
||||
let n = 512;
|
||||
let circle = (0..=n).map(|i| {
|
||||
let t = remap(i as f64, 0.0..=(n as f64), 0.0..=TAU);
|
||||
let r = self.circle_radius as f64;
|
||||
let r = self.circle_radius;
|
||||
Value::new(
|
||||
r * t.cos() + self.circle_center.x as f64,
|
||||
r * t.sin() + self.circle_center.y as f64,
|
||||
@@ -108,25 +108,25 @@ impl PlotDemo {
|
||||
}
|
||||
|
||||
fn sin(&self) -> Curve {
|
||||
let n = 512;
|
||||
let circle = (0..=n).map(|i| {
|
||||
let t = remap(i as f64, 0.0..=(n as f64), -TAU..=TAU);
|
||||
Value::new(t / 5.0, 0.5 * (self.time + t).sin())
|
||||
});
|
||||
Curve::from_values_iter(circle)
|
||||
.color(Color32::from_rgb(200, 100, 100))
|
||||
.name("0.5 * sin(x / 5)")
|
||||
let time = self.time;
|
||||
Curve::from_explicit_callback(
|
||||
move |x| 0.5 * (2.0 * x).sin() * time.sin(),
|
||||
f64::NEG_INFINITY..=f64::INFINITY,
|
||||
512,
|
||||
)
|
||||
.color(Color32::from_rgb(200, 100, 100))
|
||||
.name("0.5 * sin(2x) * sin(t)")
|
||||
}
|
||||
|
||||
fn thingy(&self) -> Curve {
|
||||
let n = 512;
|
||||
let complex_curve = (0..=n).map(|i| {
|
||||
let t = remap(i as f64, 0.0..=(n as f64), 0.0..=TAU);
|
||||
Value::new((2.0 * t + self.time).sin(), (3.0 * t).sin())
|
||||
});
|
||||
Curve::from_values_iter(complex_curve)
|
||||
.color(Color32::from_rgb(100, 150, 250))
|
||||
.name("x = sin(2t), y = sin(3t)")
|
||||
let time = self.time;
|
||||
Curve::from_parametric_callback(
|
||||
move |t| ((2.0 * t + time).sin(), (3.0 * t).sin()),
|
||||
0.0..=TAU,
|
||||
512,
|
||||
)
|
||||
.color(Color32::from_rgb(100, 150, 250))
|
||||
.name("x = sin(2t), y = sin(3t)")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user