fix: migrate & fix av-sync
This commit is contained in:
parent
c30bffac73
commit
597aff5784
5 changed files with 51 additions and 32 deletions
|
|
@ -8,21 +8,25 @@
|
||||||
import FlashIndicator from './components/FlashIndicator.svelte';
|
import FlashIndicator from './components/FlashIndicator.svelte';
|
||||||
import Scale from './components/Scale.svelte';
|
import Scale from './components/Scale.svelte';
|
||||||
|
|
||||||
export let frame = 0;
|
interface Props {
|
||||||
export let fps = 60;
|
frame?: number;
|
||||||
export let debug = false;
|
fps?: number;
|
||||||
|
debug?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { frame = $bindable(0), fps = $bindable(60), debug = $bindable(false) }: Props = $props();
|
||||||
|
|
||||||
|
window.setFps = async (newFps: number) => {
|
||||||
|
fps = newFps;
|
||||||
|
await tick();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.setFrame = async (frameNumber: number) => {
|
||||||
|
frame = frameNumber;
|
||||||
|
await tick();
|
||||||
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
window.setFps = async (newFps: number) => {
|
|
||||||
fps = newFps;
|
|
||||||
await tick();
|
|
||||||
};
|
|
||||||
|
|
||||||
window.setFrame = async (frameNumber: number) => {
|
|
||||||
frame = frameNumber;
|
|
||||||
await tick();
|
|
||||||
};
|
|
||||||
|
|
||||||
if (window.location.search.includes('debug')) {
|
if (window.location.search.includes('debug')) {
|
||||||
debug = true;
|
debug = true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,24 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let frame: number;
|
interface Props {
|
||||||
export let fps: number;
|
frame: number;
|
||||||
|
fps: number;
|
||||||
|
}
|
||||||
|
|
||||||
let el: SVGSVGElement;
|
let { frame, fps }: Props = $props();
|
||||||
$: center = el?.clientWidth / 2;
|
|
||||||
$: radius = center;
|
|
||||||
|
|
||||||
let opacity = 1;
|
let el: SVGSVGElement | undefined = $state();
|
||||||
$: opacity = ease(1 - ((frame % fps) / fps) * 2);
|
|
||||||
|
let opacity = $state(1);
|
||||||
|
|
||||||
function ease(x: number) {
|
function ease(x: number) {
|
||||||
x = Math.max(0, Math.min(1, x));
|
x = Math.max(0, Math.min(1, x));
|
||||||
return 1 - Math.cos((x * Math.PI) / 2);
|
return 1 - Math.cos((x * Math.PI) / 2);
|
||||||
}
|
}
|
||||||
|
let center = $derived((el?.clientWidth ?? 0) / 2);
|
||||||
|
let radius = $derived(center);
|
||||||
|
$effect(() => {
|
||||||
|
opacity = ease(1 - ((frame % fps) / fps) * 2);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svg class="indicator" bind:this={el} style="--opacity: {opacity}">
|
<svg class="indicator" bind:this={el} style="--opacity: {opacity}">
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let frame: number;
|
interface Props {
|
||||||
export let fps: number;
|
frame: number;
|
||||||
|
fps: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { frame, fps }: Props = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="scale" style="--frame: {frame}; --fps: {fps}">
|
<div class="scale" style="--frame: {frame}; --fps: {fps}">
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,18 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let frame: number;
|
interface Props {
|
||||||
export let fps: number;
|
frame: number;
|
||||||
|
fps: number;
|
||||||
|
}
|
||||||
|
|
||||||
let el: SVGSVGElement;
|
let { frame, fps }: Props = $props();
|
||||||
$: center = el?.clientWidth / 2;
|
|
||||||
$: radius = center;
|
|
||||||
let d = '';
|
|
||||||
let circleOpacity = 1;
|
|
||||||
|
|
||||||
$: {
|
let el: SVGSVGElement | undefined = $state();
|
||||||
|
let center = $derived((el?.clientWidth ?? 0) / 2);
|
||||||
|
let radius = $derived(center);
|
||||||
|
let d = $state('');
|
||||||
|
let circleOpacity = $state(1);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
const angle = ((frame / fps) * 360) % 360;
|
const angle = ((frame / fps) * 360) % 360;
|
||||||
const radians = (angle * Math.PI) / 180;
|
const radians = (angle * Math.PI) / 180;
|
||||||
const x = center + radius * Math.cos(radians);
|
const x = center + radius * Math.cos(radians);
|
||||||
|
|
@ -17,7 +21,7 @@
|
||||||
|
|
||||||
const flashFrames = fps / 10;
|
const flashFrames = fps / 10;
|
||||||
circleOpacity = (flashFrames - (frame % fps)) / flashFrames;
|
circleOpacity = (flashFrames - (frame % fps)) / flashFrames;
|
||||||
}
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svg class="indicator" style="--circle-opacity: {circleOpacity}" bind:this={el}>
|
<svg class="indicator" style="--circle-opacity: {circleOpacity}" bind:this={el}>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import './app.css';
|
import './app.css';
|
||||||
import App from './App.svelte';
|
import App from './App.svelte';
|
||||||
|
import { mount } from "svelte";
|
||||||
|
|
||||||
const app = new App({
|
const app = mount(App, {
|
||||||
target: document.getElementById('app')!
|
target: document.getElementById('app')!
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue