Drawing shapes interactive
How do I make an drawing shapes interactive?
Drawing some shapes.. What is a drawing shapes interactive? How do you make a drawing shapes interactive? This script and codes were developed by Erik Terwan on 04 July 2022, Monday.
Drawing shapes interactive - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Drawing shapes interactive</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="main"></canvas> <script src="js/index.js"></script>
</body>
</html>
Drawing shapes interactive - Script Codes CSS Codes
body
{ margin: 0; padding: 0; background: #000;
}
canvas#main
{ width: 100%; height: 100%; background: #000; position: absolute; top: 0; left: 0;
}
Drawing shapes interactive - Script Codes JS Codes
(function(body){ var canvas = document.getElementById('main'), ctx = canvas.getContext('2d'), t = 0, a = 500, c = 200, x = 0, y = 0, mouseX = 0, mouseY = 0, randX = 0, randY = 0, lifetime = 0, colorUp = false, settings = { speed: 0.1, lineWidth : 1, linesEveryNumFrames: 10, minHue : 100, maxHue : 225, hueSpeed : 2.1, }; function setup() { setSizes(); t = 0; c = 200; lifetime = 0; colorUp = false; settings = { speed: 0.01, lineWidth : 1, linesEveryNumFrames: 3, minHue : 100, maxHue : 225, hueSpeed : 0.1, }; draw(); } function setSizes() { w = canvas.width = window.innerWidth, h = canvas.height = window.innerHeight, mouseX = randX = x = x2 = w / 2, mouseY = randY = y = y2 = h / 2, a = Math.max(w, h); } function draw() { if(lifetime %2 == 0){ ctx.shadowBlur = 0; ctx.shadowColor= "hsla(0, 0%, 0%, 0)"; ctx.fillStyle = "hsla(0,0%,0%,0.05)"; ctx.fillRect(0,0,w,h); } var xa = (a * Math.cos(t)); xa = xa / (1 + Math.pow( Math.sin(t), 2)); var ya = (a * Math.sin(t) * Math.cos(t)); ya = ya / (1 + Math.pow(Math.cos(t), 2)); xa += w / 2; ya += h / 2; if(lifetime %250 == 0){ randX = (Math.random() * w); randY = (Math.random() * h); } var dx = mouseX - x; if(Math.abs(dx) > 1) { x += dx * 0.03; } var dy = mouseY - y; if(Math.abs(dy) > 1) { y += dy * 0.03; } var dx2 = randX - x2; if(Math.abs(dx2) > 1) { x2 += dx2 * 0.01; } var dy2 = randY - y2; if(Math.abs(dy2) > 1) { y2 += dy2 * 0.01; } ctx.beginPath(); ctx.shadowBlur = 10; ctx.shadowColor= "hsla("+c+", 89%, 35%, 0.5)"; ctx.lineWidth = settings.lineWidth; ctx.bezierCurveTo(x,y,x2,y2,xa, ya); //ctx.quadraticCurveTo(startX,startY,xRand,yRand,x, y); ctx.strokeStyle = "hsla("+c+", 99%, 68%, 0.5)"; ctx.stroke(); ctx.closePath(); //} if(colorUp){ c += settings.hueSpeed; } else{ c -= settings.hueSpeed; } if(c > settings.maxHue){ c = settings.maxHue; colorUp = false; } else if(c < settings.minHue){ c = settings.minHue; colorUp = true; } t += settings.speed; lifetime++; window.requestAnimationFrame(draw); } document.addEventListener('DOMContentLoaded', setup, false); window.addEventListener('resize', setSizes, false); document.addEventListener('mousemove', function(e) { mouseX = e.pageX; mouseY = e.pageY; }, false);
})(document.body);
Developer | Erik Terwan |
Username | erikterwan |
Uploaded | July 04, 2022 |
Rating | 3 |
Size | 2,569 Kb |
Views | 42,504 |
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!
Name | Size |
Canvas Template | 1,746 Kb |
Livestream Audio Visualizer v2 | 5,771 Kb |
Math.random at work | 2,535 Kb |
Drawing lines somewhat interactive. | 2,486 Kb |
Drawing lines | 2,292 Kb |
Connecting dots | 2,622 Kb |
Shape by attraction | 2,757 Kb |
Particle Storm - PixiJS | 2,789 Kb |
A Pen by Erik Terwan | 26,016 Kb |
Moving shape | 2,555 Kb |
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!
Name | Username | Size |
SVG Circle Progress | JMChristensen | 3,368 Kb |
Drag in vanilla js using dotval math instead of translate | Paulq | 2,662 Kb |
A form arranged using automatic placement. | Vikasford | 2,103 Kb |
Toggle Time | Petebot | 5,345 Kb |
Exploding Text | Jjmartucci | 4,749 Kb |
Masonry | Uriuriuriu | 5,005 Kb |
SCSS Unit Conversion | Jakob-e | 8,210 Kb |
Loading Bar | Jaradlight | 2,333 Kb |
My three.js practice | Esambino | 3,203 Kb |
Portfolio Layout Flex | Lahvjal | 3,489 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!