( area: BBox, duration = 0.6, )
| 14 | * @param duration - The duration of the transition. |
| 15 | */ |
| 16 | export function* zoomOutTransition( |
| 17 | area: BBox, |
| 18 | duration = 0.6, |
| 19 | ): ThreadGenerator { |
| 20 | const scale = useScene().getSize().div(area.size); |
| 21 | |
| 22 | const currentPosition = Vector2.createSignal( |
| 23 | area.position.flipped.mul(scale), |
| 24 | ); |
| 25 | const currentScale = Vector2.createSignal(scale); |
| 26 | const previousPosition = Vector2.createSignal(0); |
| 27 | const previousScale = Vector2.createSignal(1); |
| 28 | const alpha = createSignal(0); |
| 29 | |
| 30 | const endTransition = useTransition( |
| 31 | ctx => { |
| 32 | ctx.globalAlpha = clampRemap(0.1, 0.5, 0, 1, alpha()); |
| 33 | ctx.translate(currentPosition.x(), currentPosition.y()); |
| 34 | ctx.scale(currentScale.x(), currentScale.y()); |
| 35 | }, |
| 36 | ctx => { |
| 37 | ctx.globalAlpha = clampRemap(0.5, 0.9, 1, 0, alpha()); |
| 38 | ctx.translate(previousPosition.x(), previousPosition.y()); |
| 39 | ctx.scale(previousScale.x(), previousScale.y()); |
| 40 | }, |
| 41 | ); |
| 42 | |
| 43 | const timing = (v: number) => easeInOutCubic(Math.sqrt(v)); |
| 44 | yield* all( |
| 45 | currentPosition(Vector2.zero, duration, timing), |
| 46 | previousPosition(area.position, duration, timing), |
| 47 | currentScale(1, duration, timing), |
| 48 | previousScale(Vector2.one.div(scale), duration, timing), |
| 49 | alpha(1, duration, linear), |
| 50 | ); |
| 51 | |
| 52 | endTransition(); |
| 53 | } |
nothing calls this directly
no test coverage detected