-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app): pass theme to render correct color
- Loading branch information
Showing
2 changed files
with
123 additions
and
124 deletions.
There are no files selected for viewing
239 changes: 121 additions & 118 deletions
239
app/src/lib/components/spinning-outline-logo-three.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,130 @@ | ||
<script lang="ts"> | ||
import * as THREE from 'three'; | ||
<script lang="ts"> | ||
import * as THREE from 'three'; | ||
import Square from './spinning-logo/square.svelte'; | ||
import { onMount } from 'svelte'; | ||
import { createCube } from '$lib/three/cube'; | ||
import { mode, userPrefersMode } from "mode-watcher"; | ||
let cubeWidth = 128; | ||
let gap = 64; | ||
let cubeCount = 16; | ||
// let cubeWidth = 128; | ||
// let gap = 80; | ||
// let cubeCount = 16; | ||
let logoWidth = cubeWidth * cubeCount + gap * (cubeCount - 1); | ||
let cubesY = cubeWidth * 2 + gap; | ||
$: cubeDelta = (20 - cubeWidth) / 2; | ||
let strokeWidth = 2.5; | ||
let threeContainer: HTMLElement; | ||
let threeCanvas: HTMLCanvasElement; | ||
const render = (mode: string) => { | ||
const scene = new THREE.Scene(); | ||
const renderer = new THREE.WebGLRenderer({ antialias: true, canvas: threeCanvas, alpha: true }); | ||
const devicePixelRatio = window.devicePixelRatio || 1; | ||
renderer.setPixelRatio(devicePixelRatio); | ||
renderer.setClearColor(0x000000, 0); | ||
const camera = new THREE.PerspectiveCamera(20, 2, 1, 4000); | ||
const startCameraZ = cubeWidth * 5; | ||
const sideCameraOffset = cubeWidth * 3; | ||
camera.position.z = startCameraZ; | ||
let cubes: Array<THREE.Group> = []; | ||
for (let x = 0; x < cubeCount; x++) { | ||
const cube = createCube(cubeWidth, strokeWidth, mode); | ||
cube.position.z = 0; | ||
cube.position.x = (x * (cubeWidth + gap)); | ||
cube.rotation.x = x * ((Math.PI / 2) / cubeCount); | ||
cubes.push(cube); | ||
scene.add(cube); | ||
} | ||
function resizeCanvasToDisplaySize() { | ||
const canvas = renderer.domElement; | ||
const width = canvas.clientWidth; | ||
const height = canvas.clientHeight; | ||
if (canvas.width !== width || canvas.height !== height) { | ||
renderer.setSize(width, height, false); | ||
camera.aspect = width / height; | ||
camera.updateProjectionMatrix(); | ||
} | ||
} | ||
const clock = new THREE.Clock(); | ||
// start with going through the cubes | ||
let animationState: "SLIDING_RIGHT" | "ROTATING_RIGHT" | "SLIDING_LEFT" | "ROTATING_LEFT" = "SLIDING_LEFT"; | ||
camera.rotation.y = Math.PI / 2; | ||
camera.position.z = 0; | ||
camera.position.x = logoWidth + sideCameraOffset; | ||
function animate(time: number) { | ||
const secs = clock.getDelta() * 0.65; | ||
resizeCanvasToDisplaySize(); | ||
if (animationState === "SLIDING_RIGHT") { | ||
camera.position.x += (secs * 150); | ||
if (camera.position.x >= logoWidth + sideCameraOffset) { | ||
animationState = "ROTATING_RIGHT"; | ||
} | ||
} else if (animationState === "ROTATING_RIGHT") { | ||
const rotating = camera.rotation.y < Math.PI / 2; | ||
const translating = camera.position.z > 0; | ||
if (!rotating && !translating) { | ||
animationState = "SLIDING_LEFT"; | ||
} | ||
if (rotating) { | ||
camera.rotation.y += secs * 0.4 | ||
} | ||
if (translating) { | ||
camera.position.z -= secs * 160; | ||
} | ||
} else if (animationState === "SLIDING_LEFT") { | ||
if (camera.position.x > -sideCameraOffset) { | ||
camera.position.x -= (secs * 150); | ||
} else { | ||
animationState = "ROTATING_LEFT"; | ||
} | ||
} else if (animationState === "ROTATING_LEFT") { | ||
const rotating = camera.rotation.y > 0; | ||
const translating = camera.position.z < startCameraZ; | ||
if (!rotating && !translating) { | ||
animationState = "SLIDING_RIGHT"; | ||
} | ||
if (rotating) { | ||
camera.rotation.y -= secs * 4.00 | ||
} | ||
if (translating) { | ||
camera.position.z += secs * 400; | ||
} | ||
} | ||
cubes.forEach((cube, index) => { | ||
cube.rotation.x += secs * -2 * (((cubeCount - index) + 1) / (cubeCount + 1)) | ||
}) | ||
renderer.render(scene, camera); | ||
requestAnimationFrame(animate); | ||
// console.log(clock.elapsedTime); | ||
} | ||
requestAnimationFrame(animate); | ||
} | ||
onMount(render) | ||
$: render($mode) | ||
let cubeWidth = 128; | ||
let gap = 64; | ||
let cubeCount = 16; | ||
// let cubeWidth = 128; | ||
// let gap = 80; | ||
// let cubeCount = 16; | ||
let logoWidth = cubeWidth * cubeCount + gap * (cubeCount - 1); | ||
let cubesY = cubeWidth * 2 + gap; | ||
$: cubeDelta = (20 - cubeWidth) / 2; | ||
let strokeWidth = 2.5; | ||
let threeContainer: HTMLElement; | ||
let threeCanvas: HTMLCanvasElement; | ||
onMount(() => { | ||
const scene = new THREE.Scene(); | ||
const renderer = new THREE.WebGLRenderer({ antialias: true, canvas: threeCanvas, alpha: true }); | ||
const devicePixelRatio = window.devicePixelRatio || 1; | ||
renderer.setPixelRatio(devicePixelRatio); | ||
renderer.setClearColor(0x000000, 0); | ||
const camera = new THREE.PerspectiveCamera(20, 2, 1, 4000); | ||
const startCameraZ = cubeWidth * 5; | ||
const sideCameraOffset = cubeWidth * 3; | ||
camera.position.z = startCameraZ; | ||
let cubes: Array<THREE.Group> = []; | ||
for (let x = 0; x < cubeCount; x++) { | ||
const cube = createCube(cubeWidth, strokeWidth); | ||
cube.position.z = 0; | ||
cube.position.x = (x * (cubeWidth + gap)); | ||
cube.rotation.x = x * ((Math.PI/2)/cubeCount); | ||
cubes.push(cube); | ||
scene.add(cube); | ||
} | ||
function resizeCanvasToDisplaySize() { | ||
const canvas = renderer.domElement; | ||
const width = canvas.clientWidth; | ||
const height = canvas.clientHeight; | ||
if (canvas.width !== width || canvas.height !== height) { | ||
renderer.setSize(width, height, false); | ||
camera.aspect = width / height; | ||
camera.updateProjectionMatrix(); | ||
} | ||
} | ||
const clock = new THREE.Clock(); | ||
// start with going through the cubes | ||
let animationState: "SLIDING_RIGHT" | "ROTATING_RIGHT" | "SLIDING_LEFT" | "ROTATING_LEFT" = "SLIDING_LEFT"; | ||
camera.rotation.y = Math.PI/2; | ||
camera.position.z = 0; | ||
camera.position.x = logoWidth + sideCameraOffset; | ||
function animate(time: number) { | ||
const secs = clock.getDelta() * 0.65; | ||
resizeCanvasToDisplaySize(); | ||
if (animationState === "SLIDING_RIGHT") { | ||
camera.position.x += (secs * 150); | ||
if (camera.position.x >= logoWidth + sideCameraOffset) { | ||
animationState = "ROTATING_RIGHT"; | ||
} | ||
} | ||
else if (animationState === "ROTATING_RIGHT") { | ||
const rotating = camera.rotation.y < Math.PI/2; | ||
const translating = camera.position.z > 0; | ||
if (!rotating && !translating) { | ||
animationState = "SLIDING_LEFT"; | ||
} | ||
if (rotating) { | ||
camera.rotation.y += secs * 0.4 | ||
} | ||
if (translating) { | ||
camera.position.z -= secs * 160; | ||
} | ||
} | ||
else if (animationState === "SLIDING_LEFT") { | ||
if (camera.position.x > -sideCameraOffset) { | ||
camera.position.x -= (secs * 150); | ||
} else { | ||
animationState = "ROTATING_LEFT"; | ||
} | ||
} | ||
else if (animationState === "ROTATING_LEFT") { | ||
const rotating = camera.rotation.y > 0; | ||
const translating = camera.position.z < startCameraZ; | ||
if (!rotating && !translating) { | ||
animationState = "SLIDING_RIGHT"; | ||
} | ||
if (rotating) { | ||
camera.rotation.y -= secs * 4.00 | ||
} | ||
if (translating) { | ||
camera.position.z += secs * 400; | ||
} | ||
} | ||
cubes.forEach((cube, index) => {cube.rotation.x += secs * -2 * (((cubeCount - index) + 1)/(cubeCount + 1))}) | ||
renderer.render(scene, camera); | ||
requestAnimationFrame(animate); | ||
// console.log(clock.elapsedTime); | ||
} | ||
requestAnimationFrame(animate); | ||
}); | ||
</script> | ||
|
||
<div class="relative flex-1"> | ||
<div class="absolute size-full" bind:this={threeContainer}> | ||
<canvas class="size-full" bind:this={threeCanvas}></canvas> | ||
<div bind:this={threeContainer} class="absolute size-full"> | ||
<canvas bind:this={threeCanvas} class="size-full"></canvas> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters