Skip to content

choochburger/starfield

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Animated Canvas Starfield

image

Usage:

var starfield = Starfield.create(element, options)

  • element is an HTMLElement (the container to insert the canvas into)
  • options is an object containing options (optional)

Examples can be found here.

Options:

Defaults explained:

numStars:   20,     // Number of stars used in field
speedMin:   10,     // Minimum speed
speedMax:   80,     // Maximum speed
radiusMin:  1,      // Minimum pixel radius of "stars"
radiusMax:  4,      // Maximum pixel radius of "stars"
width:      null,   // Width of the starfield
height:     null,   // Height of the starfield
bgColor:    '#000', // Background color (HEX, rgba, etc)
starColors: ['#FFF', '#DDD', '#444', '#333'], // Array of colors to randomly assign to the "stars"
frameMs:    50      // Time between frames (in milliseconds)

You can pass in all or none of these values to the Starfield constructor.

Example:

var fieldEl = document.getElementById('field');

Starfield.create(fieldEl, {
  starColors: ['#980000', '#FF0000', '#FF9900'] // Fiery hell stars. Ahhhhhh.
});

API

var starfield = Starfield.create(element, options);

starfield.start() // Star animation
starfield.pause() // Pause animation

About

Simple animated canvas starfield (also good for snow)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages