Skip to content

Commit a8d788f

Browse files
committed
Add particle effect hero page
1 parent 6aaf7b6 commit a8d788f

File tree

4 files changed

+3056
-2214
lines changed

4 files changed

+3056
-2214
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
"@fortawesome/free-brands-svg-icons": "^6.4.2",
1919
"@fortawesome/free-solid-svg-icons": "^6.4.2",
2020
"@fortawesome/react-fontawesome": "^0.2.0",
21+
"@tsparticles/engine": "^3.4.0",
22+
"@tsparticles/react": "^3.0.0",
23+
"@tsparticles/slim": "^3.4.0",
2124
"babel-plugin-styled-components": "^2.1.4",
2225
"gatsby": "^5.12.3",
2326
"gatsby-cli": "^5.12.0",
@@ -36,7 +39,8 @@
3639
"react": "^18.2.0",
3740
"react-dom": "^18.2.0",
3841
"react-helmet": "^6.1.0",
39-
"styled-components": "^6.0.7"
42+
"styled-components": "^6.0.7",
43+
"tsparticles-slim": "^2.12.0"
4044
},
4145
"devDependencies": {
4246
"prettier": "3.0.3"

src/sections/hero.js

Lines changed: 80 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { graphql, useStaticQuery } from 'gatsby'
2-
import React from 'react'
2+
import React, { useState, useEffect, useMemo } from 'react'
33
import styled from 'styled-components'
44
import { GatsbyImage, getImage, withArtDirection } from 'gatsby-plugin-image'
5+
import Particles, { initParticlesEngine } from '@tsparticles/react'
6+
import { loadSlim } from '@tsparticles/slim'
7+
import { starbound } from '../styling'
58

69
const HeroContainer = styled.div`
710
position: relative;
@@ -66,7 +69,7 @@ const HeroSubtitle = styled.h2`
6669
}
6770
`
6871

69-
export default function Hero() {
72+
function _HeroFractalImage() {
7073
const hero = useStaticQuery(graphql`
7174
query HeroImageQuery {
7275
mobile: file(relativePath: { eq: "images/fractal-mobile.png" }) {
@@ -99,15 +102,83 @@ export default function Hero() {
99102
}
100103
])
101104

105+
return (
106+
<GatsbyImage
107+
image={responsiveImages}
108+
style={{
109+
gridArea: '1/1',
110+
zIndex: -1
111+
}}
112+
/>
113+
)
114+
}
115+
116+
function HeroParticles() {
117+
const [init, setInit] = useState(false);
118+
119+
useEffect(() => {
120+
initParticlesEngine(async (engine) => {
121+
console.log(engine)
122+
await loadSlim(engine)
123+
})
124+
.then(() => setInit(true))
125+
}, [])
126+
127+
const options = useMemo(() => ({
128+
fpsLimit: 60,
129+
detectRetina: true,
130+
pauseOnOutsideViewport: true,
131+
fullScreen: false,
132+
particles: {
133+
color: {
134+
value: [
135+
starbound.lightBlue,
136+
starbound.orange,
137+
starbound.yellow,
138+
starbound.white
139+
],
140+
},
141+
links: {
142+
enable: true,
143+
opacity: 0.5,
144+
color: starbound.white,
145+
triangles: {
146+
enable: true,
147+
opacity: 0.01
148+
}
149+
},
150+
number: {
151+
value: 70,
152+
limit: 100,
153+
density: { enable: true }
154+
},
155+
move: {
156+
enable: true,
157+
speed: 1,
158+
random: true,
159+
gravity: { acceleration: 0.1 }
160+
},
161+
opacity: {
162+
value: { min: 0.2, max: 1.0 },
163+
animation: {
164+
enable: true,
165+
speed: 0.01
166+
}
167+
}
168+
}
169+
}), [])
170+
171+
return <div style={{ gridArea: '1/1', zIndex: -1 }}>
172+
{ init && <Particles style={{
173+
position: 'inherit !important'
174+
}} options={options}/> }
175+
</div>
176+
}
177+
178+
export default function Hero() {
102179
return (
103180
<HeroContainer>
104-
<GatsbyImage
105-
image={responsiveImages}
106-
style={{
107-
gridArea: '1/1',
108-
zIndex: -1
109-
}}
110-
/>
181+
<HeroParticles/>
111182
<HeroText>
112183
<HeroTitle
113184
data-sal="slide-up"

src/styling/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ export const primary = '#00b6e8'
44
export const darkPrimary = '#154bb2'
55
export const secondary = '#ea9300'
66

7+
export const starbound = {
8+
darkPurple: '#12101c',
9+
purple: '#4d15b2',
10+
blue: '#154bb2',
11+
lightBlue: '#00b6e8',
12+
red: '#ea3900',
13+
orange: '#ea9300',
14+
yellow: '#e8e200',
15+
white: '#e3dad3'
16+
}
17+
718
export default createGlobalStyle`
819
:root {
920
--black: #000000;
@@ -16,7 +27,7 @@ export default createGlobalStyle`
1627
--orange: #ea9300;
1728
--yellow: #e8e200;
1829
--white: #e3dad3;
19-
30+
2031
--star-gradient: linear-gradient(45deg, var(--red) 0%, var(--orange) 20%, var(--yellow) 80%, var(--white));
2132
--sky-gradient: linear-gradient(45deg, var(--purple) 0%, var(--blue) 50%, var(--light-blue));
2233
--space-gradient: linear-gradient(45deg, var(--less-black), var(--dark-purple));
@@ -77,4 +88,10 @@ export default createGlobalStyle`
7788
ul > li {
7889
margin: 8pt 0pt;
7990
}
91+
92+
#tsparticles {
93+
position: absolute !important;
94+
width: 100%;
95+
height: 100%;
96+
}
8097
`

0 commit comments

Comments
 (0)