FRENAR
N°08 · Vanilla JS · Tactile & Physique

Physique de drag

Deux objets, deux physiques : le carré plein rebondit en spring (ressort) vers son origine ; le carré creux dérive par inertie quand vous le lancez. Comparez le ressenti.

SPRING
INERTIA
attrapez · lancez
// Spring physics — Hooke's law + damping
function springStep(pos, target, velocity, stiffness, damping) {
  const force = (target - pos) * stiffness / 100;
  velocity += force;
  velocity *= 1 - damping / 100;
  pos += velocity;
  return { pos, velocity };
}

// Inertia — velocity decay + boundary bounce
function inertiaStep(pos, velocity, friction, min, max) {
  pos += velocity;
  velocity *= friction / 100;
  if (pos < min || pos > max) {
    velocity *= -0.6; // rebond mur
    pos = Math.max(min, Math.min(max, pos));
  }
  return { pos, velocity };
}
À toi de jouer

Mettez la raideur à 80 et l'amortissement à 2 — l'objet spring oscille longtemps (sous-amorti). À quel rapport le mouvement est-il « critique » (retour sans oscillation) ?

Interfaces vivantes, physique maîtrisée

Réserver un créneau