Skip to content

Commit

Permalink
Merge pull request #52 from binhtran432k/fix/bg-anim
Browse files Browse the repository at this point in the history
fix(background): make animation smoother
  • Loading branch information
binhtran432k authored Aug 28, 2024
2 parents 6ed20d5 + ab45b07 commit 53f0ac6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components/landing/landing.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { component$, useSignal, useVisibleTask$ } from "@builder.io/qwik";
import backgroundImage from "~/assets/background.jpg";
import coolBackground from "~/utils/cool-background";
import { coolBackground } from "~/utils/cool-background";
import Header from "../header/header";
import Intro from "../intro/intro";
import ScrollDown from "../scroll-down/scroll-down";
Expand Down
9 changes: 5 additions & 4 deletions src/utils/cool-background.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as THREE from "three";

export default function (container: Element, image: string) {
export function coolBackground(container: Element, image: string) {
const scene = new THREE.Scene();
const loader = new THREE.TextureLoader();
const camera = new THREE.PerspectiveCamera(70, getCameraAspect(), 0.1, 1000);

const renderer = new THREE.WebGLRenderer({
antialias: true,
antialias: false,
});

handleSetRendererSize(renderer);
Expand Down Expand Up @@ -48,7 +48,8 @@ function animate(opts: {
opts.renderer.render(opts.scene, opts.camera);
}

const MAX_FRAME = 30;
const MAX_FRAME = 60;
const TIME_FACTOR = MAX_FRAME / 4;
const waveEffects: number[][] = [];
function calculateWaveEffects(geometry: THREE.PlaneGeometry, count: number) {
for (let frame = 0; frame < MAX_FRAME; frame++) {
Expand All @@ -71,7 +72,7 @@ function animateWaveEffect(
time: number,
count: number,
) {
const frame = Math.round(time * 8) % MAX_FRAME;
const frame = Math.round(time * TIME_FACTOR) % MAX_FRAME;
if (oldFrame === frame) {
return;
}
Expand Down

0 comments on commit 53f0ac6

Please sign in to comment.