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 |
Canvas experiment 2 | 2,903 Kb |
Calculator | 4,493 Kb |
Zen quote generator | 8,480 Kb |
Portfolio | 9,868 Kb |
Canvas experiment 3 | 3,609 Kb |
Canvas experiment 1 | 3,412 Kb |
Tribute to Peter Singer | 2,090 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 |
Loading animation - freedom purchase | Rocbear | 2,567 Kb |
Growing Root - Scroll control - CANVAS | Cjonasw | 2,342 Kb |
Material Design-Layout-Principles Practice | Fraina | 2,331 Kb |
Midterm dry run | Jds317 | 1,649 Kb |
Wip elementary os navbar | Nickcolley | 2,993 Kb |
A Pen by Ash | Littleginger | 2,386 Kb |
Replace url via jquery | Serluk | 1,429 Kb |
Board Site | IndianaLuft | 10,542 Kb |
My Starter Kit For Codepen | Dkdesign | 2,012 Kb |
Starfield using KineticJS | Asp | 3,512 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!