1.0.1 • Published 5 years ago

react-canvas-js v1.0.1

Weekly downloads
352
License
MIT
Repository
github
Last release
5 years ago

react-canvas-js (demo)

:rocket: Awesome HTML Canvas animations in React!

NPM JavaScript Style Guide

Install

npm install --save react-canvas-js

Usage

import React, { Component } from 'react'
import Canvas from 'react-canvas-js'

const particleOptions = [
  {
    'maxParticles': 50,
    'colors': ['#2E1D62', '#513D91', '#487EEF', '#11A887', '#fc5c65', '#fed330'],
    'shapes': ['circle', 'square'],
    'size': 10,
    'minSpeed': 0.05,
    'maxSpeed': 0.20,
    'alpha': 0.70,
    'backgroundColor': '#1E1F29'
  }
]

class Example extends Component {
  render () {
    return (
      <Canvas options={particleOptions} />
    )
  }
}

Available Options

OptionTypeRequiredDefaultDescription
precisionNumberNo2The precision to use for all float values in the component.
backgroundColorStringNo'#f1f1f1'The background color for the canvas.
maxParticlesNumberNo50Maximum number of particles to include in Animation.
colorStringNoOne of ['red', 'green', 'yellow']The color for all Particles.
colors[String]No['red', 'green', 'yellow']The range of colors to randomly pick for each particle.
shapeObject/StringNoOne of ['circle', 'square', 'rectangle']The Shape of the particle.
shape.typeString (One of ['image', 'rectangle', 'square', 'circle'])NonullThe shape type (supported shapes are ['image', 'rectangle', 'square', 'circle']).
shape.srcStringNo / Yes (if type === 'image')nullThe image src, if type is set to image.
shape.sizeNumber || ObjectNoInherits Parent size property.The size of the particle.
shape.size.widthNumberNoInherits Parent size property.The width of the particle.
shape.size.heightNumberNoInherits Parent size property.The height of the particle.
shape.size.radiusNumberNoInherits Parent size property.The radius of the particle if shape is 'circle'.
shape.colorStringNoInherits Parent color property.
shapes[Object/String]No['circle', 'square', 'rectangle']The range of shapes to randomly pick for each particle.
minSizeNumberNo10The minimum size (range) for the particle sizes, to be picked at random (if size not defined).
maxSizeNumberNo10The maximum size (range) for the particle sizes, to be picked at random (if size not defined).
minSpeedNumberNo0.05The speed for each particle is taken at random in between the min(Speed) / max(Speed) range
maxSpeedNumberNo0.09The speed for each particle is taken at random in between the min(Speed) / max(Speed) range
alphaNumberNo0.5The alpha/transparency for the canvas particles/elements.
debugOptionsObjectNonullDeveloper Debugging options
debugOptions.enabledbooleanYesfalseEnables debugging, and binds a Particle object to window.Particle to inspect.
debugOptions.attachAllParticlesbooleanNofalseBinds all the Particle objects to window.Particles.
debugOptions.showFrameRatebooleanNoShows a frame rate blurb over the canvas, indicating the frame rate achieved by that canvas.

Planned Features (checklist)

  • Add interaction support.
    • Add support for custom hover handler (#1).
    • Add support for custom click handler (#2).
    • Add support for custom Keyboard key(s) handler (#3).
  • Add tests (#4).
  • Identify possible Optimizations (#5).
  • Particle/subject animation control, i.e. Support for controlling movement, scale and transform of Particle/subject from current given x,y coordinates to xn, yn coordinates over given duration or speed (#6).

My goal is to progress to more than just Particle animation, by simplifying and adding support for all canvas animation use cases. Suggestions and feedback are welcome too.

Contributing

I could use some assistance in building and improving this component. I'll welcome pull requests for bug fixes, new features, improvements and writing test cases. If you are interested head on over to the Issues section, and pick up any of the issue(s) that interest you. The issues with label need help could really do with some help (as the label suggests). Please create your pull requests to the develop branch. Top Contributors will be added here under the contributors section (if you'd like that).

Author

Shalom Sam

  • Checkout my Full Stack Web Developer Website
  • You can checkout this React Portfolio here
  • A scope of my work @ React Portfolio

License

MIT © shalomsam