responsive-image-canvas/src/utils/motionPresets.ts
BaekRyang f6ad8b11b0 feat: Add motion presets for distortion animations
- 왜곡 애니메이션에 사용할 수 있는 다양한 모션 프리셋(horizontal, vertical, rotate-cw 등)을 추가했습니다.
- `DistortionMovement` 인터페이스에 `preset`과 `strength` 옵션을 추가하여 모션 프리셋을 설정할 수 있도록 변경했습니다.
- `presetToVector` 함수와 `isRotationPreset` 함수를 추가하여 모션 프리셋 로직을 구현했습니다.
- `AnimationLoop` 클래스에서 모션 프리셋을 적용하여 `vectorA`를 계산하도록 수정했습니다.
2025-11-24 13:41:36 +09:00

54 lines
1.3 KiB
TypeScript

import type {MotionPreset, Point} from '../types';
/**
* 모션 프리셋을 벡터로 변환
* @param preset 모션 프리셋
* @param strength 모션 강도 (기본값: 0.1)
* @returns 계산된 벡터 (vectorA)
*/
export function presetToVector(preset: MotionPreset, strength: number = 0.1): Point {
switch (preset) {
case 'none':
// 애니메이션 없음
return {x: 0, y: 0};
case 'horizontal':
// 좌우 왕복
return {x: strength, y: 0};
case 'vertical':
// 상하 왕복
return {x: 0, y: strength};
case 'rotate-cw':
// 시계방향 회전 (원운동의 시작점)
return {x: strength, y: 0};
case 'rotate-ccw':
// 반시계방향 회전 (원운동의 시작점)
return {x: -strength, y: 0};
case 'pulse':
// 펄스 (중심에서 바깥으로)
return {x: strength, y: strength};
case 'diagonal-1':
// 대각선 (좌상→우하)
return {x: strength * 0.707, y: strength * 0.707}; // √2/2 ≈ 0.707
case 'diagonal-2':
// 대각선 (우상→좌하)
return {x: strength * 0.707, y: -strength * 0.707};
default:
return {x: 0, y: 0};
}
}
/**
* 프리셋이 회전 타입인지 확인
*/
export function isRotationPreset(preset?: MotionPreset): boolean {
return preset === 'rotate-cw' || preset === 'rotate-ccw';
}