Electric worm

Developer
Size
2,377 Kb
Views
38,456

How do I make an electric worm?

Random math stuff using waves and more waves. Feel free to use as you wish. Doubts? just message/post me. :). What is a electric worm? How do you make a electric worm? This script and codes were developed by Jeff Ibacache on 23 June 2022, Thursday.

Electric worm Previews

Electric worm - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Electric worm</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>

Electric worm - Script Codes CSS Codes

body {	margin: 0;	padding: 0;	background: #FFF;
};	canvas {	position: absolute;	width: 100%;	height: 100%;
}

Electric worm - Script Codes JS Codes

var canvas;
var context;
var screenWidth;
var screenHeight;
var doublePI = Math.PI * 2;
var step = 30;
var offset = 0;
window.onload = function()
{	canvas = document.getElementById('canvas'); context = canvas.getContext('2d'); window.onresize = function()	{	screenWidth = window.innerWidth;	screenHeight = window.innerHeight;	canvas.width = screenWidth;	canvas.height = screenHeight;	};	window.onresize(); loop();
};
window.getAnimationFrame =
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback)
{	window.setTimeout(callback, 16.6);
};
function loop()
{	context.fillStyle = '#282828';	context.fillRect(0, 0, screenWidth, screenHeight);	render();	step += 0.1;	offset += Math.sin(step * 0.01) * 0.04;	getAnimationFrame(loop);
}
function render()
{	if(Math.random() > 0.05) drawWave(180, 160, 15, false, 0);	if(Math.random() > 0.8) drawWave(180, 160, 1, false, 8);
}
function drawWave(sw, sh, lineWidth, fill, randomFactor)
{	var i = 22;	var length = 64;	context.beginPath();	context.lineWidth = lineWidth;	context.strokeStyle = '#FFF';	context.fillStyle = '#FFF';	context.lineJoin = "round";	context.lineCap = "round";	for(i; i <= length; ++i)	{	var norm = (i / length);	var angle = doublePI * norm;	var wave = norm * (Math.cos(step * 0.1) * 48 + 64);	var x = Math.cos(angle + (Math.PI / 2) + offset) * (Math.cos(step * 0.6) * 20 + sw) + Math.cos(wave + step + offset) * (Math.sin(step + offset) * 8) + Math.cos(wave * 0.5 + step + offset) * 12 + (1 - (Math.random() * 2) * randomFactor);	var y = Math.sin(angle + (Math.PI / 2) + offset) * (Math.sin(step) * 20 + sh) + Math.sin(wave + step + offset) * (Math.cos(step + offset) * 8) + Math.sin(wave * 0.5 + step + offset) * 16 + (1 - (Math.random() * 2) * randomFactor);	if(i === 0) context.moveTo(x + (screenWidth >> 1), y + (screenHeight >> 1));	else context.lineTo(x + (screenWidth >> 1), y + (screenHeight >> 1));	if(!fill) context.stroke();	else context.fill();	}	context.closePath();
}
Electric worm - Script Codes
Electric worm - Script Codes
Home Page Home
Developer Jeff Ibacache
Username jeffibacache
Uploaded June 23, 2022
Rating 4
Size 2,377 Kb
Views 38,456
Do you need developer help for Electric worm?

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!

Jeff Ibacache (jeffibacache) 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!