npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jdfranel/snowflake-generator

v1.0.1

Published

Generates svg snowflakes using Bronian tree.

Downloads

2

Readme

Snowflake Generator

A Snowflake generator using Bronian tree method. From a snowflake you can create an SVG view using a path or multiple points.

This implementation is based on Daniel Shiffman's Coding Challenge 127: Brownian Motion Snowflake impementation using p5.js.

It works in both Node.js and the browser.

More informations on the drawing of a snowflake on this code challenge - Draw a Snowflake page.

Installation

Node.js

npm install @jdfranel/snowflake-generator --save
const SnowflakeGenerator = require('@jdfranel/snowflake-generator');
var snowflake = SnowflakeGenerator.create();

Global object

Include the pre-built script.

<script src="./build/snowflake-generator.js"></script>
<script>
var snowflake = SnowflakeGenerator.create();
</script>

Build

npm run build

Documentation

SnowflakeGenerator

public static create(particleDistance: number): Snowflake

Returns an initiated snowflake with 1 particle. This snowflake can have more particle until the particleDistance is reached.

particleDistance: The distance at witch particles will start to get to the snowflake

public static generate(particleDistance: number): Snowflake

Returns a fully grown snowflake using snowflake.generate(). Depending of the particleDistance the generation of a snowflake can take some time (around 1.3s for a distance of 500).

particleDistance: The distance at witch particles will start to get to the snowflake

Snowflake

constructor(distance: number = 500)

Creates a new snowflake to be generated with 1 particle. distance: The distance at witch particles will start to get to the snowflake

public isDone(): boolean

Indicates if the snowflake is completed.

public generate(): void

Generate the snowflake by using addParticle() until isDone().

public addParticle(): number

Adds a patricle to the snowflake. Returns The number of moves needed to make the particle meet the snowflake or -1 if the snowflake is already completed.

public getParticles(): Particle[]

Returns the particle array.

public toSVG(size: number = 100): ViewElement

Generates an SVG path representation of the particles composing the snowflake. size: The width and height of the svg output.

public toSVGPath(size?: number): ViewElement

Generates an SVG path representation of the particles composing the snowflake. size: The width and height of the svg output.

public toSVGDots(size?: number): ViewElement

Generates an SVG dots representation of the particles composing the snowflake. size: The width and height of the svg output

ViewElement

The ViewElement class exists to allow the library to generate the SVG structure and convert it as a platform compatible format.

public toDomElement(): Element

Generates an SVG DOM Element that you can append into your document when using Snowflake generator in a browser.

public toString(): string

Generates an string representation of the SVG Element that you can print, save or do whatever you need when using Snowflake generator as a nodejs module.

Particle

The Particle class is not of much interest to generate the snowflake but you can tweek the update() function to fit your likings.

Most of the time you will want to get the particle position using the following:

particle.pos: Victor

The position of the particle is stored in a Victor.js 2d vector.

Demo

You can find a single web page demo that show how you can manipulate a snowflake and render it.

The demo can be found in the ./web folder.

Credits

License

MIT

Donate

In case you want to compensate all the snowy fun you have by a beer, you will need this.

  • BTC : 37kyGHUfAh7zJ3znaBNhspgHMXddimztox
  • ETH : 0x705C45Dcf60EFc7aF6521B4211940dBB7d25aFF5