Last active
December 29, 2023 15:45
-
-
Save IharKrasnik/ab03427e47fc8de1e9171d4ebbf99455 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvas = window.backgroundCanvas; | |
var doc = document; | |
function bgAnimate(){ | |
canvas.width = window.innerWidth; | |
canvas.height = window.innerHeight; | |
if(canvas.getContext) { | |
var context = canvas.getContext('2d'); | |
var w = canvas.width; | |
var h = canvas.height; | |
/* | |
var img = document.getElementById("star"); | |
context.drawImage("#star",5,5); | |
*/ | |
context.strokeStyle = 'rgba(255,255,255,0.3)'; | |
context.lineWidth = 4; | |
context.lineCap = 'round'; | |
var init = []; | |
var maxParts =50; | |
for(var i = 0; i < maxParts; i++) { | |
init.push({ | |
x: Math.random() * w, | |
y: Math.random() * h, | |
l: Math.random() * 1, | |
xs: -4 + Math.random() * 4 + 2, | |
ys: Math.random() * 10 + 1 | |
}) | |
} | |
var particles = []; | |
for(var i = 0; i < maxParts; i++) { | |
particles[i] = init[i]; | |
} | |
function draw() { | |
context.clearRect(0, 0, w, h); | |
for(var i = 0; i < particles.length; i++) { | |
var particle = particles[i]; | |
context.beginPath(); | |
context.moveTo(particle.x, particle.y); | |
context.lineTo(particle.x + particle.l * particle.xs, particle.y + particle.l * particle.ys); | |
context.stroke(); | |
} | |
move(); | |
} | |
function move() { | |
for(var b = 0; b < particles.length; b++) { | |
var particle = particles[b]; | |
particle.x += particle.xs; | |
particle.y += particle.ys; | |
if(particle.x > w || particle.y > h) { | |
particle.x = Math.random() * w; | |
particle.y = 20; | |
} | |
} | |
} | |
setInterval(draw, 50); | |
} | |
}; | |
bgAnimate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment