Canvas experiment 3

Size
3,609 Kb
Views
36,432

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 Previews

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();
}
Canvas experiment 3 - Script Codes
Canvas experiment 3 - Script Codes
Home Page Home
Developer Justin Richardsson
Username hallaathrad
Uploaded August 31, 2022
Rating 3
Size 3,609 Kb
Views 36,432
Do you need developer help for Canvas experiment 3?

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!

Justin Richardsson (hallaathrad) Script Codes
Create amazing blog posts with AI!

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!