Home > Web Front-end > HTML Tutorial > HTML5 Canvas realistic smoke effect js plug-in

HTML5 Canvas realistic smoke effect js plug-in

黄舟
Release: 2017-01-18 14:30:03
Original
2322 people have browsed it

Brief Tutorial

smoke.js is a realistic smoke effects js plug-in based on HTML5 Canvas. Through this js plug-in, you can easily create various smoke effects on the page.

Usage method

Introduce the smoke.js file into the page.

<script type="text/javascript" src="js/smoke.js"></script>
Copy after login

HTML structure

Use a element as a container.

<canvas id="canvas"></canvas>
Copy after login

Initialize the plug-in

Use the following method at the bottom of the page to initialize the smoke effect plug-in.

var canvas = document.getElementById(&#39;canvas&#39;)
var ctx = canvas.getContext(&#39;2d&#39;)
canvas.width = 1000
canvas.height = 1000
 
var party = smokemachine(ctx, [54, 16.8, 18.2])
 
party.start() // start animating
 
party.addsmoke(500,500,10) // wow we made smoke
 
setTimeout(function(){
 
    party.stop() // stop animating
 
    party.addsmoke(600,500,100)
    party.addsmoke(500,600,20)
 
    for(var i=0;i<10;i++){
        party.step(10) // pretend 10 ms pass and rerender
    }
 
    setTimeout(function(){
        party.start()
    },1000)
 
},1000)
Copy after login

API

The APIs available for this smoke effect plug-in are:

  • ##smokemachine(context, [r,g,b]): Returns a Smoke instance.


  • #context - The canvas on which smoke is drawn.

  • [r,g,b] - (optional) The color of the smoke

  • var party = smokemachine(context, [1,5,253])
    Copy after login
    • party.start (): Start smoke animation.

    • party.stop(): End the smoke animation.

    • party.addsmoke(x,y,numberofparticles):

    • x,y — The coordinates of the smoke created in the canvas.

    • numberofparticles — Creates more smoke.

    • party.step(milliseconds): How many milliseconds after which the smoke will be redrawn.

    The above is the content of the HTML5 Canvas realistic smoke effect js plug-in. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template