Skip to content

Commit

Permalink
Reworks the CRT effect
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianoratamero committed Aug 17, 2024
1 parent f89b7bd commit 3ddc7c7
Show file tree
Hide file tree
Showing 5 changed files with 822 additions and 8 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"type": "module",
"dependencies": {
"comfy.js": "^1.1.16",
"dat.gui": "^0.7.9",
"lodash-es": "^4.17.21",
"nice-color-palettes": "^3.0.0",
"tmi.js": "^1.8.5"
Expand Down
54 changes: 46 additions & 8 deletions src/routes/effects/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<script lang="ts">
import { base } from '$app/paths';
import { page } from '$app/stores';
import scanlines from '$lib/img/scanlines.png';
import { onMount } from 'svelte';
import Confetti from 'svelte-confetti';
import { ScreenEffect, initGUI } from './crt';
import './crt/main.scss';
let crt_effect_enabled = $state(false);
let crt_root: HTMLElement | undefined = $state();
let crt_effect: ScreenEffect | undefined = $state();
let crt_open_gui = $state(false);
let confetti_effect_enabled = $state(false);
let bokeh_effect_enabled = $state(false);
let bokeh_options: { transparentBg?: string; bookmark?: string; decay?: string } = {};
let bokeh_options_string = $derived(new URLSearchParams(bokeh_options).toString());
Expand All @@ -16,6 +22,10 @@
if (search_params.has('crt')) {
crt_effect_enabled = true;
if (search_params.has('openGUI')) {
crt_open_gui = true;
}
}
if (search_params.has('confetti')) {
confetti_effect_enabled = true;
Expand All @@ -33,10 +43,44 @@
}
}
});
$effect(() => {
document.querySelector('.dg.ac')?.remove();
if (crt_effect_enabled && crt_root && !crt_effect) {
crt_effect = new ScreenEffect('#screen', {
effects: {
vignette: { enabled: true },
vcr: {
enabled: true,
options: {
opacity: 1,
miny: 220,
miny2: 220,
num: 70,
fps: 60
}
},
wobbley: { enabled: true },
snow: {
enabled: true,
options: {
opacity: 0.2
}
}
}
});
crt_effect.start();
if (crt_open_gui) {
initGUI(crt_effect, crt_effect.config);
} else {
document.querySelector('.dg.ac')?.remove();
}
}
});
</script>

{#if crt_effect_enabled}
<img src={scanlines} class="crt size fixed h-full w-full bg-cover" alt="CRT background effect" />
<div id="screen" bind:this={crt_root}></div>
{/if}

{#if confetti_effect_enabled}
Expand All @@ -60,9 +104,3 @@
class="fixed h-full w-full bg-cover"
></iframe>
{/if}

<style>
.crt {
background-size: 100% 1px;
}
</style>
Loading

0 comments on commit 3ddc7c7

Please sign in to comment.