Pointed
How do I make an pointed?
Learning canvas and brushing up on math. Started out with a single arrow, decided to tile them and decrease opacity based on distance. What is a pointed? How do you make a pointed? This script and codes were developed by Nick Williams on 27 August 2022, Saturday.
Pointed - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Pointed</title> <meta name="viewport" content="width=device-width"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="controls"> <label> Spacing: <input type="range" id="spacing" min="10" max="99" step="1" /> <output></output> </label> </div> <canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>
Pointed - Script Codes CSS Codes
body { margin:0; font-family: sans-serif;; } canvas { display: block; } .controls { position: absolute; top : 0; right: 0; padding: 0.75em 1em; background-color: rgba(0,0,0,0.75); color: white; }
Pointed - Script Codes JS Codes
/* global requestAnimationFrame */
var pixelRatio = window.devicePixelRatio || 1;
function initCanvas(elem, width, height) { elem.width = (width * pixelRatio); elem.height = (height * pixelRatio); elem.style.height = "100%"; elem.style.width = "100%"; var context = elem.getContext("2d"); context.scale(pixelRatio, pixelRatio); return context;
}
window.onload = function() { var width = window.innerWidth; var height = window.innerHeight; var canvas = document.querySelector("#canvas"); var context = initCanvas(canvas, width, height); var spacing = 50; var radius = Math.min(width, height); var mouseX = width / 2; var mouseY = height / 2; function clear(context, width, height) { context.clearRect(0, 0, width, height); } function drawArrow(context, x, y, angle, color) { context.save(); context.translate(x, y); context.rotate(angle); context.beginPath(); context.moveTo(20, 0); context.lineTo(-20, 0); context.moveTo(20, 0); context.lineTo(10, -10); context.moveTo(20, 0); context.lineTo(10, 10); context.lineWidth = 3; context.strokeStyle = color; context.stroke(); context.restore(); } function getColor(dx, dy) { var dist = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); var alpha = 1 - (dist / radius); return "rgba(0,0,0," + Math.max(0.2, alpha) + ")"; } function render() { clear(context, width, height); for(var arrowX = spacing / 2; arrowX < width; arrowX += spacing) { for(var arrowY = spacing / 2; arrowY < (height); arrowY += spacing) { var dx = mouseX - arrowX; var dy = mouseY - arrowY; var angle = Math.atan2(dy, dx); var color = getColor(dx, dy); drawArrow(context, arrowX, arrowY, angle, color); } } requestAnimationFrame(render); } render(); var output = document.querySelector("output"); var slider = document.querySelector("#spacing"); slider.value = spacing; output.innerHTML = spacing + "px"; slider.addEventListener("input", function(e) { spacing = this.valueAsNumber; output.innerHTML = spacing + "px"; }); document.addEventListener("mousemove", function(e) { mouseX = e.clientX; mouseY = e.clientY; }, false); document.addEventListener("touchmove", function(e) { var touch = e.touches[0]; mouseX = touch.clientX; mouseY = touch.clientY; });
};
Developer | Nick Williams |
Username | WickyNilliams |
Uploaded | August 27, 2022 |
Rating | 4.5 |
Size | 2,630 Kb |
Views | 34,408 |
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 |
Pointed | 2,630 Kb |
A Pen by Nick Williams | 1,616 Kb |
Closure classic | 1,842 Kb |
Headroom.js demo | 3,982 Kb |
Gridzzz | 3,199 Kb |
Conditional Lightbox for Responsive Design | 2,792 Kb |
Block, Element, Modifier in LESS | 1,735 Kb |
Bokeh | 4,253 Kb |
React starter template | 1,957 Kb |
JS module pattern demo | 4,111 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 |
Haml Calendar | Katydecorah | 5,643 Kb |
Mesmerizing octopus | Jllodra | 3,549 Kb |
Simple DevTools | Deegill | 2,511 Kb |
CSS3 Butterfly | Timohausmann | 3,430 Kb |
Expandable Left Side Bar with jQuery animate | Retrofuturistic | 2,483 Kb |
Custom checkbox example | Capelo | 3,495 Kb |
Isometric css island | Xaddict | 2,950 Kb |
Week7 replicate | Hwcasis | 1,620 Kb |
Knob rotation | Alemesre | 2,122 Kb |
A Pen by utcwebdev | Utcwebdev | 2,856 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!