Skip to content

Commit

Permalink
Flip sway direction after drag has ended
Browse files Browse the repository at this point in the history
  • Loading branch information
philippamarkovics committed Sep 28, 2024
1 parent f9e71e3 commit fe0d80b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tent.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@
let prevTime = performance.now();
let phase = 0;
let tfs = coords;
let direction = -1;

function sway(t) {
if (!swaying) return;
let dT = t - prevTime;
prevTime = t;
phase += dT * 0.0009;
let offset = Math.sin(phase);
let offset = Math.sin(phase) * direction;
tfs = {
t: { x: coords.t.x - offset * 15, y: coords.t.y - offset * 10 },
bfl: { x: coords.bfl.x - offset * 20, y: coords.bfl.y - offset * 3 },
Expand Down Expand Up @@ -206,6 +207,7 @@
function onDragEnd(event, d) {
coords = Object.assign({}, coords, tfs);
coords[d.id] = { x: d.fx, y: d.fy };
direction = direction * -1;
phase = 0;
prevTime = performance.now();
swaying = true;
Expand Down

0 comments on commit fe0d80b

Please sign in to comment.