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 |
Gridzzz | 3,199 Kb |
Headroom.js demo | 3,982 Kb |
Block, Element, Modifier in LESS | 1,735 Kb |
Conditional Lightbox for Responsive Design | 2,792 Kb |
React starter template | 1,957 Kb |
A Pen by Nick Williams | 1,616 Kb |
Closure classic | 1,842 Kb |
Particle particulars | 3,688 Kb |
Got your callback | 2,451 Kb |
Bokeh | 4,253 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 |
Pagepilling.js | Blossk | 6,554 Kb |
Base-Style | Daniel_gooss | 2,614 Kb |
SCSS Simple Animated Drop-In | Danwarfel | 2,175 Kb |
React Markdown Previewer | C0d0er | 3,190 Kb |
Draggables in pure angular | Rlo206 | 5,167 Kb |
Bootstrap 3 Price Table | Honglio | 2,655 Kb |
A vuejs widget | Chrgl86 | 2,869 Kb |
Part 19 Bootstrap split button dropdown | Venkatesha | 1,601 Kb |
Rows with image hover effect | Amit-webdesigner | 12,875 Kb |
About Us | Francescaedits | 1,902 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!