Toggle navigation
Sign Up
Log In
Explore
Works
Folders
Tools
Collections
Artists
Groups
Groups
Topics
Tasks
Tasks
Jobs
Teams
Jobs
Recommendation
More Effects...
JS
var canvas; var stage; var width = 650; var height = 400; var particles = []; var max = 60; var mouseX=0; var mouseY=0; var speed=3; var size=20; //The class we will use to store particles. It includes x and y //coordinates, horizontal and vertical speed, and how long it's //been "alive" for. function Particle(x, y, xs, ys) { this.x=x; this.y=y; this.xs=xs; this.ys=ys; this.life=0; } function init() { //Reference to the HTML element canvas=document.getElementById("game"); canvas.width = document.width; canvas.height = document.height; width=canvas.width; height=canvas.height; mouseX=canvas.width/2; mouseY=canvas.height*0.8; //See if the browser supports canvas if (canvas.getContext) { //Get the canvas context to draw onto stage = canvas.getContext("2d"); //Makes the colors add onto each other, producing //that nice white in the middle of the fire stage.globalCompositeOperation="lighter"; //Update the mouse position canvas.addEventListener("mousemove", getMousePos); window.addEventListener("resize", function() { canvas.width = document.width; canvas.height = document.height; width=canvas.width; height=canvas.height; stage.globalCompositeOperation="lighter"; mouseX=canvas.width/2; mouseY=canvas.height*0.8; }); //Update the particles every frame var timer=setInterval(update,40); } else { alert("Canvas not supported."); } } function getMousePos (evt) { var rect = canvas.getBoundingClientRect(); var root = document.documentElement; // return mouse position relative to the canvas mouseX = evt.clientX - rect.left - root.scrollLeft; mouseY = evt.clientY - rect.top - root.scrollTop; } function update() { //Adds ten new particles every frame for (var i=0; i<10; i++) { //Adds a particle at the mouse position, with random horizontal and vertical speeds var p = new Particle(mouseX, mouseY, (Math.random()*2*speed-speed)/2, 0-Math.random()*2*speed); particles.push(p); } //Clear the stage so we can draw the new frame stage.clearRect(0, 0, width, height); //Cycle through all the particles to draw them for (i=0; i
= max) { particles.splice(i, 1); i--; } } } init();
CSS
* { margin: 0; padding: 0;} body, html {width:100%; height:100%;} canvas {display:block;}
HTML
Join Effecthub.com
Working with Global Gaming Artists and Developers!
Login
Sign Up
Or Login with Your Email Address:
Email
Password
Remember
Or Sign Up with Your Email Address:
Your Email
This field must contain a valid email
Set Password
Password should be at least 1 character
Stay informed via email