mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
[emath] RectTransform: transforms Pos2 from one Rect to another
Very useful for transforming coordinate systems, e.g. for painting
This commit is contained in:
@@ -34,6 +34,9 @@ impl super::View for DancingStrings {
|
||||
let desired_size = ui.available_width() * vec2(1.0, 0.35);
|
||||
let (_id, rect) = ui.allocate_space(desired_size);
|
||||
|
||||
let to_screen =
|
||||
math::RectTransform::from_to(Rect::from_x_y_ranges(0.0..=1.0, -1.0..=1.0), rect);
|
||||
|
||||
let mut shapes = vec![];
|
||||
|
||||
for &mode in &[2, 3, 5] {
|
||||
@@ -46,11 +49,7 @@ impl super::View for DancingStrings {
|
||||
let t = i as f32 / (n as f32);
|
||||
let amp = (time as f32 * speed * mode).sin() / mode;
|
||||
let y = amp * (t * std::f32::consts::TAU / 2.0 * mode).sin();
|
||||
|
||||
pos2(
|
||||
lerp(rect.x_range(), t),
|
||||
remap(y, -1.0..=1.0, rect.y_range()),
|
||||
)
|
||||
to_screen * pos2(t, y)
|
||||
})
|
||||
.collect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user