Skip to content

Commit

Permalink
aa
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaoticLeah committed Dec 7, 2024
1 parent a4f8fb4 commit 2ec182a
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 57 deletions.
92 changes: 92 additions & 0 deletions deno.lock

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
},
"dependencies": {
"@lottiefiles/dotlottie-web": "^0.38.1",
"@pixi/display": "^7.4.2",
"@pixi/particle-emitter": "^5.0.8",
"daisyui": "^4.12.14",
"particle-emitter": "^0.5.0",
"pixi.js": "^8.6.3",
"pixijs": "^7.1.4"
},
Expand Down
2 changes: 1 addition & 1 deletion src/app.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities'
@import 'tailwindcss/utilities'
40 changes: 27 additions & 13 deletions src/app.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>

<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>

<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>

</html>

<style>
Expand All @@ -21,20 +24,31 @@
}

body {
cursor: url('mouse.svg'), auto;
cursor: url('mouse.svg') 14 14, auto;
}

a,
button,
[role='button'],
input[type='button'],
input[type='submit'] {
cursor: url('mouseClick.svg'), pointer !important;
cursor: url('mouseClick.svg') 14 14, pointer !important;
}

@media (prefers-reduced-motion: reduce) {
* {
cursor: auto; /*reverts to the default cursor */
cursor: auto;
/*reverts to the default cursor */
}
}
</style>

.frosted-glass {
/* From https://css.glass */
background: rgba(255, 255, 255, 0.1);
border-radius: 16px;
box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
backdrop-filter: blur(9.6px);
-webkit-backdrop-filter: blur(9.6px);
border: 1px solid rgba(255, 255, 255, 0.3);
}
</style>
129 changes: 115 additions & 14 deletions src/lib/components/Pixi.svelte
Original file line number Diff line number Diff line change
@@ -1,28 +1,129 @@
<script lang="ts">
//@ts-ignore
import { Application } from 'pixi.js';
import { Application, Assets, MeshRope, Point, Texture } from 'pixi.js';
//@ts-ignore
import * as particles from '@pixi/particle-emitter';
import { Container } from '@pixi/display';
import { onMount } from 'svelte';
// const { Container, ParticleContainer, Renderer, Ticker } = PIXI;
let div: HTMLDivElement;
// Asynchronous IIFE
(async () => {})();
$effect(() => {
// // Asynchronous IIFE
// (async () => {})();
// $effect(() => {
// });
onMount(() => {
// Mouse position variable.
// let mousePosition = { x: 0, y: 0 };
// // Track mouse movements.
// window.addEventListener('mousemove', (event) => {
// mousePosition = { x: event.clientX, y: event.clientY };
// });
if (!div) return;
(async () => {
const app = new Application({
width: 800,
height: 600,
backgroundColor: 0x1099bb,
resolution: window.devicePixelRatio || 1
});
const app = new Application();
// Intialize the application.
await app.init({ background: '#1099bb', resizeTo: window });
await app.init({
backgroundAlpha: 0,
resizeTo: window,
resolution: window.devicePixelRatio || 1
});
// Then adding the application's canvas to the DOM body.
div.appendChild(app.canvas);
})();
// div.appendChild(app.view);
// Load the texture for the trail
const trailTexture = await Assets.load('trail.png');
const historyX: number[] = [];
const historyY: number[] = [];
const historySize = 20; // Determines how long the trail will be
const ropeSize = 100; // Determines how smooth the trail will be
const points: Point[] = [];
// Create history arrays to store mouse positions
for (let i = 0; i < historySize; i++) {
historyX.push(0);
historyY.push(0);
}
// Create an array of points for the rope to follow
for (let i = 0; i < ropeSize; i++) {
points.push(new Point(0, 0));
}
// Create the MeshRope object
const rope = new MeshRope({ texture: trailTexture, points });
rope.blendMode = 'add'; // Additive blend mode to make the trail brighter
app.stage.addChild(rope);
let mousePosition: { x: number; y: number } | null = null;
// Set up mousemove event listener
app.stage.eventMode = 'static';
app.stage.hitArea = app.screen;
app.stage.on('mousemove', (event) => {
mousePosition = { x: event.global.x, y: event.global.y };
});
// Animation loop to update the trail
app.ticker.add(() => {
if (!mousePosition) return;
// Update the history arrays with the current mouse position
historyX.pop();
historyX.unshift(mousePosition.x);
historyY.pop();
historyY.unshift(mousePosition.y);
// Update the points for the rope to follow
for (let i = 0; i < ropeSize; i++) {
const p = points[i];
// Smooth the trail using cubic interpolation
const ix = cubicInterpolation(historyX, (i / ropeSize) * historySize);
const iy = cubicInterpolation(historyY, (i / ropeSize) * historySize);
p.x = ix;
p.y = iy;
}
});
// Cubic interpolation function to smooth the trail
function clipInput(k: number, arr: number[]): number {
if (k < 0) k = 0;
if (k > arr.length - 1) k = arr.length - 1;
return arr[k];
}
function getTangent(k: number, factor: number, array: number[]): number {
return (factor * (clipInput(k + 1, array) - clipInput(k - 1, array))) / 2;
}
function cubicInterpolation(array: number[], t: number, tangentFactor = 1): number {
const k = Math.floor(t);
const m = [getTangent(k, tangentFactor, array), getTangent(k + 1, tangentFactor, array)];
const p = [clipInput(k, array), clipInput(k + 1, array)];
t -= k;
const t2 = t * t;
const t3 = t * t2;
return (
(2 * t3 - 3 * t2 + 1) * p[0] +
(t3 - 2 * t2 + t) * m[0] +
(-2 * t3 + 3 * t2) * p[1] +
(t3 - t2) * m[1]
);
}
})();
});
</script>

<div bind:this={div}></div>
<div bind:this={div} class="z-[-1] bg-base-200"></div>
Loading

0 comments on commit 2ec182a

Please sign in to comment.