Light rays

Developer
Size
2,677 Kb
Views
50,600

How do I make an light rays?

Simulated volumetric lighting.. What is a light rays? How do you make a light rays? This script and codes were developed by Tristan on 25 August 2022, Thursday.

Light rays Previews

Light rays - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Light rays</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Light rays - Script Codes CSS Codes

*{margin:0;padding:0;-moz-box-sizing:border-box;-webkit-box-sizing:border-box}
body{font-size:75%;background:#222;font-family:arial;padding:20px 0 0 20px}
canvas{border:1px solid #181818;display:block;box-shadow:0 0 10px #111;background:rgba(20,20,20,1)}

Light rays - Script Codes JS Codes

var canvas, c, w, h, twoPI = Math.PI * 2, mX, mY,	resize = true,	mousemove = true,	per = { x: 0, y: 0 },	mtn, trackmouse = false;
window.onload = function(){	canvas = document.createElement('canvas')	w = canvas.width = window.innerWidth - 40;	h = canvas.height = window.innerHeight - 40;	c = canvas.getContext('2d');	document.body.appendChild(canvas);	!resize || window.addEventListener('resize', function(e){ w = canvas.width = window.innerWidth - 40; h = canvas.height = window.innerHeight - 40; });	!mousemove || canvas.addEventListener('mousemove', function(e){	trackmouse = true;	mX = e.pageX-20; mY = e.pageY-20;	per = { x: mX, y: mY };	});	per = { x: w/2, y: h/2, step: 1 }	mtn = new Mountains(300,"10");	window.setInterval(animate,17);
}
function animate(){	if(!trackmouse){	per.x += per.step;	if(per.x > w)	per.step = -per.step;	if(per.x < 0)	per.step = -per.step;	} c.globalCompositeOperation = "source-over";	c.fillStyle = "rgba(20,20,20,0.2)";	c.fillRect(0,0,w,h);	mtn.draw();
}
function newGradient(gradient){	var grad;	switch(gradient.type){	case "radial":	grad = c.createRadialGradient(gradient.x1, gradient.y1, gradient.r1, gradient.x1, gradient.y1, gradient.r2);	break;	case "linear":	grad = c.createLinearGradient(gradient.x1, gradient.y1, gradient.x2, gradient.y2);	break;	}	for(var i = 0; i < gradient.stops.length; i++){	grad.addColorStop(gradient.stops[i].s, gradient.stops[i].c);	}	return grad;
}
function Mountains(peaks,seed){	var points = [];	this.init = function(){	var step = w / peaks,	y = 0;	points.push({x: 0, y: y});	for(var i = 1; i <= peaks; i++){	y = y + (Math.random() * 20)-10;	points.push({x: i * step, y: y});	}	};	this.draw = function(){	c.save();	c.fillStyle = "rgba(20,20,20,1)";	c.beginPath();	c.moveTo(points[0].x, h/2-points[0].y);	for(var p = 1; p < points.length; p++){	c.lineTo(points[p].x, h/2 - points[p].y);	}	c.lineTo(w,h);	c.lineTo(0,h);	c.closePath();	c.fill();	c.restore();	c.globalCompositeOperation = "lighter";	c.fillStyle = "rgba(30,30,20,0.1)";	for(var p = 0; p < points.length-1; p++){	var va1 = Math.atan2(h/2-points[p].y - per.y, points[p].x - per.x),	va2 = Math.atan2(h/2-points[p+1].y - per.y, points[p+1].x - per.x);	c.beginPath();	c.moveTo(points[p ].x, h/2-points[p].y);	c.lineTo(points[p+1].x, h/2-points[p+1].y);	c.lineTo(points[p+1].x + Math.cos(va2)*w, h/2-points[p+1].y + Math.sin(va2)*w);	c.lineTo(points[p ].x + Math.cos(va1)*w, h/2-points[p].y + Math.sin(va1)*w);	c.closePath();	c.fill();	}	};	this.init();
}
Light rays - Script Codes
Light rays - Script Codes
Home Page Home
Developer Tristan
Username sinthetyc
Uploaded August 25, 2022
Rating 3.5
Size 2,677 Kb
Views 50,600
Do you need developer help for Light rays?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Tristan (sinthetyc) Script Codes
Create amazing marketing copy with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!