Skip to content

Commit

Permalink
fix(color): read color from snowflake config
Browse files Browse the repository at this point in the history
This allows the color of snowflakes to update properly after initialization
  • Loading branch information
cahilfoley committed Jun 9, 2019
1 parent 470f427 commit 60676a9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
7 changes: 3 additions & 4 deletions lib/Snowflake.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/Snowfall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ const Snowfall = ({ color = '#dee4fd', snowflakeCount = 150, style }: SnowfallPr
}, [render])

useEffect(() => {
console.log('useEffect')
loop()
return () => cancelAnimationFrame(animationFrame.current)
}, [loop])
Expand Down
7 changes: 3 additions & 4 deletions src/Snowflake.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const defaultConfig: SnowflakeProps = {
}

interface SnowflakeParams {
color: string
x: number
y: number
radius: number
Expand All @@ -40,9 +39,9 @@ class Snowflake {
this.config = config

// Setting initial parameters
const { color, radius, wind, speed } = this.fullConfig
const { radius, wind, speed } = this.fullConfig

this.params = {
color,
x: random(0, canvas.offsetWidth),
y: random(-canvas.offsetHeight, 0),
radius: random(...radius),
Expand All @@ -67,7 +66,7 @@ class Snowflake {
if (ctx) {
ctx.beginPath()
ctx.arc(this.params.x, this.params.y, this.params.radius, 0, 2 * Math.PI)
ctx.fillStyle = this.params.color
ctx.fillStyle = this.fullConfig.color
ctx.closePath()
ctx.fill()
}
Expand Down

0 comments on commit 60676a9

Please sign in to comment.