Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework background gradient meshes and add dots effect #335

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions app/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,35 +183,42 @@ function RootDocument({ children }: { children: React.ReactNode }) {

// Configuration for gradient blobs
const blobs = [
// Do Red, Orange, Yellow, Green, Blue, Turquoise
{
direction: [Math.random() * 1, Math.random() * 1],
color: { h: 10, s: 100, l: 50 },
}, // Red
color: { h: 184, s: 100, l: 50 }, // turquoise from logo sky
},
{
direction: [Math.random() * 1, Math.random() * 1],
color: { h: 40, s: 100, l: 50 },
}, // Yellow
color: { h: 42, s: 100, l: 50 }, // orange from logo sun
},
{
direction: [Math.random() * 1, Math.random() * 1],
color: { h: 150, s: 100, l: 50 },
}, // Green
color: { h: 341, s: 94, l: 50 }, // red from logo sunchair
},
{
direction: [Math.random() * 1, Math.random() * 1],
color: { h: 200, s: 100, l: 50 },
}, // Blue
color: { h: 184, s: 100, l: 50 }, // turquoise from logo sky (second instance)
},
{
direction: [Math.random() * 1, Math.random() * 1],
color: { h: 42, s: 100, l: 50 }, // orange from logo sun (second instance)
},
{
direction: [Math.random() * 1, Math.random() * 1],
color: { h: 341, s: 94, l: 50 }, // red from logo sunchair (second instance)
},
].map((blob, i) => ({
...blob,
x: Math.random() * canvas.width,
y: Math.random() * canvas.height,
r: Math.random() * 500 + 700,
r: Math.max(Math.random() * canvas.height, 200), // at least 200
colorH: blob.color.h,
colorS: blob.color.s,
colorL: blob.color.l,
colorA: 1,
}))

const movementSpeed = 1
const movementSpeed = 0.5

// Animate the blobs
function animate() {
Expand All @@ -229,7 +236,6 @@ function RootDocument({ children }: { children: React.ReactNode }) {
})

blobs.forEach((blob, i) => {
// Create a radial gradient for each blob[...blobs].forEach((blob, i) => {
blob.x += blob.direction[0] * movementSpeed
blob.y += blob.direction[1] * movementSpeed

Expand Down Expand Up @@ -270,11 +276,11 @@ function RootDocument({ children }: { children: React.ReactNode }) {
}
}, [])

const isHomePage = useRouterState({
select: (s) => s.location.pathname === '/',
})
// const isHomePage = useRouterState({
// select: (s) => s.location.pathname === '/',
// })

const mounted = useMounted()
// const mounted = useMounted()

return (
<html lang="en" className={themeClass}>
Expand All @@ -292,15 +298,11 @@ function RootDocument({ children }: { children: React.ReactNode }) {
</head>
<body>
<div
id="animated-background-canvas-container"
className={twMerge(
'fixed inset-0 z-0 opacity-20 pointer-events-none',
'transition-opacity duration-[2s] ease-linear',
`[&+*]:relative`,
mounted
? isHomePage
? 'opacity-10 dark:opacity-20'
: 'opacity-10 dark:opacity-20'
: 'opacity-0'
`[&+*]:relative`
)}
>
<canvas ref={canvasRef} />
Expand Down
25 changes: 23 additions & 2 deletions app/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
@tailwind utilities;

@layer base {
html,
html {
@apply bg-neutral-50 dark:bg-neutral-950;
}
body {
@apply text-gray-900 bg-gray-50 dark:bg-gray-950 dark:text-gray-200;
@apply text-gray-900 dark:text-gray-200;
/* @apply text-gray-900 bg-gray-50 dark:bg-gray-950 dark:text-gray-200; */
}

.using-mouse * {
Expand Down Expand Up @@ -34,6 +37,11 @@
border: 3px solid theme(colors.gray.100);
}

html.dark {
/* give black background to page overscroll (bounce effect on top and bottom of page) in dark mode */
background: black;
}

html.dark {
&,
* {
Expand Down Expand Up @@ -67,6 +75,19 @@
}
}

#animated-background-canvas-container {
/* First mask - the dots */
--dot-mask: radial-gradient(black 1px, transparent 1px);
/* Second mask - gradient fade out on screen edges */
--edge-mask: radial-gradient(circle at center, black 40%, transparent 120%);
/* Combine both masks */
mask-image: var(--dot-mask), var(--edge-mask);
mask-size: 4px 4px, 100% 100%; /* size for dots, size for gradient */
mask-repeat: repeat, no-repeat; /* repeat dots, don't repeat gradient */
mask-composite: intersect; /* 'intersect' shows only where both masks are visible */
mix-blend-mode: hard-light;
}

[disabled] {
@apply opacity-50 pointer-events-none;
}
Expand Down