Files
BadNote/lib/editor/engine/pen_physics.dart

33 lines
1.1 KiB
Dart
Raw Permalink Normal View History

// lib/editor/engine/pen_physics.dart
//
// Simple physical tip model: modulate stroke width by tip velocity so fountain
// ink feels slightly thinner when moving fast (starvation), while ballpoint
// stays nearly velocity-invariant.
//
// Wired at capture: PenCanvas._toNormalized and PenEditorScreen._pressureWithPhysics.
import 'brush.dart';
/// Modulate width fraction by tip velocity (page-normalized units per second).
///
/// Fountain: faster → slightly thinner (ink starvation feel).
/// Ballpoint: nearly ignore velocity.
/// Pencil: mild thinning at speed.
/// Highlighter: ignore velocity (flat marker).
double tipVelocityWidthScale(BrushKind kind, double speedNormPerSec) {
final speed =
speedNormPerSec.isNaN || speedNormPerSec < 0 ? 0.0 : speedNormPerSec;
// Reference: ~2 page-widths/sec ≈ fast handwriting; clamp influence to [0,1].
final t = (speed / 2.0).clamp(0.0, 1.0);
switch (kind) {
case BrushKind.fountainPen:
return 1.0 - 0.15 * t;
case BrushKind.ballpoint:
return 1.0 - 0.02 * t;
case BrushKind.pencil:
return 1.0 - 0.08 * t;
case BrushKind.highlighter:
return 1.0;
}
}