61 lines
2.4 KiB
Ziran
61 lines
2.4 KiB
Ziran
Desktop :: #import "kryon/desktop_runtime";
|
|
Motion :: #import "kryon/motion";
|
|
Shape :: #import "kryon/shape";
|
|
Theme :: #import "kryon/theme";
|
|
#import "kryon/drawing_props"
|
|
#import "kryon/frame_snapshot"
|
|
#import "kryon/geometry"
|
|
#import "kryon/session"
|
|
#import "kryon/tree"
|
|
|
|
week: Motion.TweenState;
|
|
week_easing: Motion.Timing;
|
|
current_week: bool = true;
|
|
|
|
// Each frame samples one value. The whole series moves on a fixed scale.
|
|
DrawSeries :: (session: Session, bounds: Rectangle, phase: float32, palette: Theme.Palette) {
|
|
grid := ColorFromPacked(palette.subtle_border)
|
|
line := ColorFromPacked(palette.accent)
|
|
shade := line
|
|
shade.a = 28
|
|
previous: [6]float32 = .{0.16, 0.26, 0.22, 0.38, 0.32, 0.42}
|
|
current: [6]float32 = .{0.20, 0.48, 0.34, 0.69, 0.63, 0.91}
|
|
points: [6]Vector2
|
|
bottom := bounds.y + bounds.height
|
|
for index: 0..4 {
|
|
y := bounds.y + bounds.height * cast(float32)index / 4.0
|
|
unused Shape.Draw(session, Shape.Props.{.start = .{bounds.x, y}, .end = .{bounds.x + bounds.width, y}, .color = grid})
|
|
}
|
|
for index: 0..5 {
|
|
value := previous[index] + (current[index] - previous[index]) * phase
|
|
points[index] = .{bounds.x + bounds.width * cast(float32)index / 5.0,
|
|
bottom - bounds.height * value}
|
|
}
|
|
for index: 0..4 {
|
|
from := points[index]
|
|
to := points[index + 1]
|
|
left := Vector2.{from.x, bottom}
|
|
right := Vector2.{to.x, bottom}
|
|
unused Shape.Triangle(session, Shape.TriangleProps.{
|
|
.first = from, .second = to, .third = right, .color = shade})
|
|
unused Shape.Triangle(session, Shape.TriangleProps.{
|
|
.first = from, .second = right, .third = left, .color = shade})
|
|
unused Shape.Draw(session, Shape.Props.{
|
|
.start = from, .end = to, .thickness = 2.5, .color = line})
|
|
}
|
|
unused Shape.Circle(session, Shape.CircleProps.{.center = points[5], .radius = 4.5, .fill = line})
|
|
}
|
|
|
|
Init :: () { week_easing = Motion.TimingFor(.EaseOut) }
|
|
|
|
SwitchWeek :: () { current_week = !current_week }
|
|
|
|
Phase :: (session: Session, theme: Theme.ThemeTokens) -> float32 {
|
|
now := cast(float64)CaptureFrameInput(session).elapsed_ms / 1000.0
|
|
target: float32 = ifx current_week then 1.0 else 0.0
|
|
phase := Motion.TweenTo(*week, target, now, 0.42 * cast(float64)theme.motion.multiplier,
|
|
week_easing, theme.motion.reduced_motion)
|
|
if phase.active { Desktop.DesktopRequestFrame() }
|
|
return phase.value
|
|
}
|