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 context; var screenH; var screenW; var stars = []; var fps = 60; var numStars = 500; $('document').ready(function() { // Calculate the screen size screenH = $(window).height(); screenW = $(window).width(); // Get the canvas canvas = $('#space'); // Fill out the canvas canvas.attr('height', screenH); canvas.attr('width', screenW); context = canvas[0].getContext('2d'); // Create all the stars for(var i = 0; i < numStars; i++) { var x = Math.round(Math.random() * screenW); var y = Math.round(Math.random() * screenH); var length = 1 + Math.random() * 1.5; var opacity = Math.random(); // Create a new star and draw var star = new Star(x, y, length, opacity); // Add the the stars array stars.push(star); } animateInterval = setInterval(animate, 1000 / fps); }); /** * Animate the canvas */ function animate() { context.clearRect(0, 0, screenW, screenH); $.each(stars, function() { this.draw(context); }) } /* stop Animation */ function stopAnimation() { clearInterval(animateInterval); } //stopAnimation(); function Star(x, y, length, opacity) { this.x = parseInt(x); this.y = parseInt(y); this.length = parseInt(length); this.opacity = opacity; this.factor = 1; this.increment = Math.random() * .03; } Star.prototype.draw = function() { context.rotate((Math.PI * 1 / 10)); // Save the context context.save(); // move into the middle of the canvas, just to make room context.translate(this.x, this.y); // Change the opacity if(this.opacity > 1) { this.factor = -1; } else if(this.opacity <= 0) { this.factor = 1; this.x = Math.round(Math.random() * screenW); this.y = Math.round(Math.random() * screenH); } this.opacity += this.increment * this.factor; context.beginPath() for (var i = 5; i--;) { context.lineTo(0, this.length); context.translate(0, this.length); context.rotate((Math.PI * 2 / 10)); context.lineTo(0, - this.length); context.translate(0, - this.length); context.rotate(-(Math.PI * 6 / 10)); } context.lineTo(0, this.length); context.closePath(); context.fillStyle = "rgba(255, 255, 200, " + this.opacity + ")"; context.shadowBlur = 5; context.shadowColor = '#fff'; context.fill(); context.restore(); }
CSS
html, body { background: linear-gradient(45deg, rgba(0,1,19,1) 0%,rgba(1,10,53,1) 15%,rgba(1,13,61,1) 60%,rgba(0,1,19,1) 100%); height: 100%; margin: 0; overflow: hidden; } #space { position: absolute; top: 0; left: 0; }
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