Canvas experiment 3
How do I make an canvas experiment 3?
Click anywhere and it'll create a dot there, unless there's already one nearby.TODO: Make the nearby dots grow or something.. What is a canvas experiment 3? How do you make a canvas experiment 3? This script and codes were developed by Justin Richardsson on 31 August 2022, Wednesday.
Canvas experiment 3 - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Canvas experiment 3</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas width="600" height="600" id="canvasHtml"> No canvas for you!
</canvas> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Canvas experiment 3 - Script Codes CSS Codes
body { background: #000; display:-webkit-box; display:-ms-flexbox; display:flex; height: 95vh; -webkit-box-align: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center;
}
canvas { background: #666;
}
Canvas experiment 3 - Script Codes JS Codes
"use strict";
var canvas = null, context = null, bufferCanvas = null, bufferCanvasCtx = null, flakeArray = [], flakeTimer = null, maxFlakes = 200;
function Flake() { this.x = Math.round(Math.random() * context.canvas.width); this.y = -10; this.drift = Math.random(); this.speed = Math.round(Math.random() * 5) + 1; this.width = (Math.random() * 3) + 2; this.height = this.width;
}
$(function init() { canvas = document.getElementById('canvasHtml'); context = canvas.getContext("2d"); bufferCanvas = document.createElement("canvas"); bufferCanvasCtx = bufferCanvas.getContext("2d"); bufferCanvasCtx.canvas.width = context.canvas.width; bufferCanvasCtx.canvas.height = context.canvas.height; // initialize the rects flakeTimer = setInterval(addFlake, 200); draw(); setInterval(animate, 30);
});
function addFlake() { flakeArray[flakeArray.length] = new Flake(); if (flakeArray.length == maxFlakes) clearInterval(flakeTimer);
}
function blank() { bufferCanvasCtx.fillStyle = "#220022"; bufferCanvasCtx.fillRect(0, 0, bufferCanvasCtx.canvas.width, bufferCanvasCtx.canvas.height);
}
function animate() { update(); draw();
}
function update() { for (var i = 0; i < flakeArray.length; i++) { if (flakeArray[i].y < context.canvas.height) { flakeArray[i].y += flakeArray[i].speed; if (flakeArray[i].y > context.canvas.height) flakeArray[i].y = -5; flakeArray[i].x += flakeArray[i].drift; if (flakeArray[i].x > context.canvas.width) flakeArray[i].x = 0; } }
}
function draw() { context.save(); //* // create a clipping region bufferCanvasCtx.beginPath(); bufferCanvasCtx.fillStyle = "black"; bufferCanvasCtx.fillRect(0, 0, bufferCanvas.width, bufferCanvas.height); bufferCanvasCtx.arc(bufferCanvas.width / 2, bufferCanvas.height / 2, bufferCanvas.height / 3, 0, 2 * Math.PI); bufferCanvasCtx.clip(); //*/ blank(); for (var i = 0; i < flakeArray.length; i++) { bufferCanvasCtx.fillStyle = "white"; bufferCanvasCtx.fillRect(flakeArray[i].x, flakeArray[i].y, flakeArray[i].width, flakeArray[i].height); } // copy the entire rendered image from the buffer canvas to the visible one context.drawImage(bufferCanvas, 0, 0, bufferCanvas.width, bufferCanvas.height); context.restore();
}
Developer | Justin Richardsson |
Username | hallaathrad |
Uploaded | August 31, 2022 |
Rating | 3 |
Size | 3,609 Kb |
Views | 36,432 |
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 |
Calculator | 4,493 Kb |
Portfolio | 9,868 Kb |
Canvas experiment 2 | 2,903 Kb |
Tribute to Peter Singer | 2,090 Kb |
Zen quote generator | 8,480 Kb |
Canvas experiment 1 | 3,412 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 |
Week7 replicate | Hwcasis | 1,620 Kb |
Em Test | Rodesco | 1,784 Kb |
Cars going | Netoguimaraes | 1,699 Kb |
Donut Chart example - MorrisJS | Capelo | 2,385 Kb |
JQuery exercise | Brian-baum | 3,780 Kb |
Scifi-style Radio-based Tab | Aaronchuo | 4,427 Kb |
Tester1 | Sasquatchbrawley | 2,001 Kb |
A Pen by Jason Kinney | Jason-kinney | 1,980 Kb |
Google Fonts Sass Mixin | HugoGiraudel | 4,237 Kb |
CMP5-Opdracht15 | SannevanGastel | 2,733 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!