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

Add support opacity for snowflake #79

Merged
merged 1 commit into from
Nov 22, 2024
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ All available properties are detailed below.
| `speed` | The minimum and maximum speed of the snowflake (in pixels per frame).<br/><br/>The speed determines how quickly the snowflake moves along the y axis (vertical speed).<br/><br/>The value for each snowflake will be randomly selected within this range. | `[1.0, 3.0]` |
| `style` | Any style properties that will be passed to the canvas element. | `undefined` |
| `wind` | The minimum and maximum wind of the snowflake (in pixels per frame).<br/><br/>The wind determines how quickly the snowflake moves along the x axis (horizontal speed).<br/><br/>The value for each snowflake will be randomly selected within this range. | `[-0.5, 2.0]` |
| `opacity` | The minimum and maximum opacity of the snowflake.<br/><br/>The value for each snowflake will be randomly selected within this range. | `[1, 1]` |

## Using Images

Expand Down
3 changes: 2 additions & 1 deletion packages/demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ snowflake.src = logo
const images = [snowflake]

const App = () => {
const { color, snowflakeCount, radius, speed, wind, useImages } = useSettingsStore()
const { color, snowflakeCount, radius, speed, wind, useImages, opacity } = useSettingsStore()

return (
<div className="app">
Expand All @@ -25,6 +25,7 @@ const App = () => {
speed={speed}
wind={wind}
images={useImages ? images : undefined}
opacity={opacity}
/>
<a className="title" href={githubURL} style={{ color }}>
<img src={logo} alt="Snowflake Logo" />
Expand Down
45 changes: 30 additions & 15 deletions packages/demo/src/components/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,36 @@ const Settings = () => {
/>
</div>
{settings.useImages ? (
<div>
<Typography gutterBottom>
Rotation Speed <ValueChip label={`Min ${settings?.rotationSpeed?.[0]}`} />
<ValueChip label={`Max ${settings?.rotationSpeed?.[1]}`} />
</Typography>
<Slider
value={settings.rotationSpeed}
min={-5}
max={10}
step={0.5}
onChange={(_, value) =>
settings.update({ rotationSpeed: value as [number, number] })
}
/>
</div>
<>
<div>
<Typography gutterBottom>
Opacity <ValueChip label={`Min ${settings?.opacity?.[0]}`} />
<ValueChip label={`Max ${settings?.opacity?.[1]}`} />
</Typography>
<Slider
value={settings.opacity}
min={0}
max={1}
step={0.1}
onChange={(_, value) => settings.update({ opacity: value as [number, number] })}
/>
</div>
<div>
<Typography gutterBottom>
Rotation Speed <ValueChip label={`Min ${settings?.rotationSpeed?.[0]}`} />
<ValueChip label={`Max ${settings?.rotationSpeed?.[1]}`} />
</Typography>
<Slider
value={settings.rotationSpeed}
min={-5}
max={10}
step={0.5}
onChange={(_, value) =>
settings.update({ rotationSpeed: value as [number, number] })
}
/>
</div>
</>
) : (
<Box my={2}>
<Typography gutterBottom>
Expand Down
3 changes: 2 additions & 1 deletion packages/demo/src/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const useSettingsStore = create<SnowfallSettings>((set) => ({
speed: [0.5, 3.0],
wind: [-0.5, 2.0],
rotationSpeed: [-1.0, 1.0],
opacity: [0.1, 0.2],
useImages: false,
update: (changes) => set(changes),
setUseImages: (useImages) => {
Expand All @@ -22,5 +23,5 @@ export const useSettingsStore = create<SnowfallSettings>((set) => ({
} else {
return set({ useImages, radius: [0.5, 3] })
}
}
},
}))
2 changes: 1 addition & 1 deletion packages/react-snowfall/lib/Snowfall.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface SnowfallProps extends Partial<SnowfallCanvasConfig> {
*/
style?: React.CSSProperties;
}
export declare const Snowfall: ({ color, changeFrequency, radius, speed, wind, rotationSpeed, snowflakeCount, images, style, }?: SnowfallProps) => JSX.Element;
export declare const Snowfall: ({ color, changeFrequency, radius, speed, wind, rotationSpeed, opacity, snowflakeCount, images, style, }?: SnowfallProps) => JSX.Element;
export default Snowfall;
3 changes: 2 additions & 1 deletion packages/react-snowfall/lib/Snowfall.js

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

2 changes: 1 addition & 1 deletion packages/react-snowfall/lib/Snowfall.js.map

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

6 changes: 6 additions & 0 deletions packages/react-snowfall/lib/Snowflake.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ export interface SnowflakeProps {
* The default value is `[-1.0, 1.0]`.
*/
rotationSpeed: [number, number];
/**
* The minimum and maximum opacity of the snowflake image.
*
* This value only applies to snowflakes that are using images.
*/
opacity: [number, number];
}
export type SnowflakeConfig = Partial<SnowflakeProps>;
export declare const defaultConfig: SnowflakeProps;
Expand Down
13 changes: 12 additions & 1 deletion packages/react-snowfall/lib/Snowflake.js

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

Loading
Loading