Trail

Draw a sharp turn and hold still. Which part of the trail disappears first?
Interactive demo#MotionAndFeel
Fading copies left behind a moving thing, showing where it has been.
The game remembers the last few positions and draws a fainter mark at each. It makes fast movement readable and gives dashes and projectiles a sense of speed.
Code
namespace trail_lesson;
import stage;
import std;
import math;
var history: f64[2][16] = [[0.0, 0.0];16];
var next = 0;
var count = 0;
fn sample(t: f64, hover: bool, x: f64, y: f64) {
history[next] = if hover { [x, y] } else { [80 + cos(t * 2) * 54, 50 + sin(t * 3.1) * 30] };
next = (next + 1) % 16;
count = min(count + 1, 16);
}
export "trail" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
artwork("draft");
if dt > 0 {
sample(time, hover, px, py);
}
else if count == 0 {
for i in 16 {
sample(time - (16 - i) * 0.016, hover, px, py);
}
}
for i in count {
let p = history[(next - count + i + 16) % 16];
let k = i / (count as f64);
opacity(k * 0.7);
let span = 2 + 6 * k;
draw_prop("crystal", p[0] - span / 2, p[1] - span * 0.64, span, span * 1.28);
}
opacity(1);
let latest = history[(next + 15) % 16];
draw_prop("crystal", latest[0] - 5, latest[1] - 7, 10, 14);
}

Comments
No comments yet.