-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
darkskittlz
committed
Oct 5, 2024
1 parent
d347089
commit 24752a8
Showing
7 changed files
with
126 additions
and
70 deletions.
There are no files selected for viewing
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,53 +1,65 @@ | ||
import React, { Component } from "react"; | ||
import ParticlesBg from "particles-bg"; | ||
import React, { Component, useEffect } from "react"; | ||
// import ParticlesBg from "particles-bg"; | ||
import { tsParticles } from "tsparticles-engine"; | ||
import { loadStarsPreset } from "tsparticles-preset-stars"; | ||
import DollarIMG from "/dollarIMG.png" | ||
|
||
export class ParticleBackground extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { | ||
name: "React" | ||
}; | ||
} | ||
export const ParticleBackground = () => { | ||
useEffect(() => { | ||
const loadParticles = async () => { | ||
// Load the stars preset into tsParticles | ||
await loadStarsPreset(tsParticles); | ||
|
||
render() { | ||
let config = { | ||
num: [7, 7], | ||
rps: 0.1, | ||
radius: [1, 40], | ||
life: [1.5, 3], | ||
v: [1, 1], | ||
tha: [-40, 40], | ||
alpha: [0.6, 0], | ||
scale: [.1, 0.4], | ||
position: "all", | ||
color: ["random", "#ff0000"], | ||
cross: "dead", | ||
// emitter: "follow", | ||
random: 15 | ||
}; | ||
|
||
if (Math.random() > 0.85) { | ||
config = Object.assign(config, { | ||
onParticleUpdate: (ctx, particle) => { | ||
ctx.beginPath(); | ||
ctx.rect( | ||
particle.p.x, | ||
particle.p.y, | ||
particle.radius * 2, | ||
particle.radius * 2 | ||
); | ||
ctx.fillStyle = particle.color; | ||
ctx.fill(); | ||
ctx.closePath(); | ||
} | ||
}); | ||
// Initialize tsParticles with the 'stars' preset | ||
await tsParticles.load("tsparticles", { | ||
preset: "stars", // Use the stars preset | ||
background: { | ||
color: { | ||
value: "#0000000" | ||
}, | ||
image: url(), | ||
position: "50% 50%", | ||
repeat: "no-repeat", | ||
size: "20%", | ||
opacity: 1 | ||
}, | ||
interactivity: { | ||
events: { | ||
onClick: { enable: true, mode: "repulse" }, | ||
onHover: { enable: true, mode: "bubble" }, | ||
resize: true | ||
} | ||
}, | ||
particles: { | ||
number: { | ||
value: 160, | ||
density: { | ||
enable: true, | ||
value_area: 800 | ||
} | ||
}, | ||
color: { | ||
value: "#ffffff" | ||
}, | ||
opacity: { | ||
value: { min: 0.1, max: 1 }, | ||
anim: { enable: true, speed: 1 } | ||
}, | ||
size: { | ||
value: { min: 1, max: 3 }, | ||
anim: { enable: true, speed: 5 } | ||
}, | ||
move: { | ||
enable: true, | ||
speed: { min: 0.1, max: 1 } | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
loadParticles(); // Call the async function when component is mounted | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<ParticlesBg type="custom" config={config} bg={true} /> | ||
</div> | ||
); | ||
} | ||
return <div id="tsparticles" style={{ position: "absolute", width: "100%", height: "100%" }}></div>; | ||
} | ||
|