Canvas experiment 1

Size
3,412 Kb
Views
40,480

How do I make an canvas experiment 1?

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 1? How do you make a canvas experiment 1? This script and codes were developed by Justin Richardsson on 31 August 2022, Wednesday.

Canvas experiment 1 Previews

Canvas experiment 1 - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Canvas experiment 1</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 1 - 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 1 - Script Codes JS Codes

"use strict";
$(function () { var canvasE = document.getElementById('canvasHtml'), canvasC = canvasE.getContext('2d'), balls = []; var Ball = (function () { function Ball(xPos, yPos, rad) { this.rad = rad || 10; this.xPos = (xPos - (this.rad / 2)) || 330; this.yPos = (yPos - (this.rad / 2)) || 10; } Ball.prototype.draw = function () { canvasC.beginPath(); canvasC.arc(this.xPos, this.yPos, this.rad, 0, Math.PI * 2); canvasC.fill(); canvasC.save(); canvasC.font = "30px Verdana"; canvasC.fillstyle = "#ffffff"; this.value = Math.round(Math.random() * 10); canvasC.fillText(this.value, 10, 50); canvasC.restore(); balls.push(this); }; Ball.prototype.drop = function () { console.log('bleh'); }; return Ball; }()); function drawBall(xPos, yPos, rad) { var ball = new Ball(xPos, yPos, rad); ball.draw(); } function checkBall(xPos, yPos) { return balls.filter(function (that) { var rad = that.rad, newXR = (xPos + rad), newXL = (xPos - rad), newYT = (yPos - rad), newYB = (yPos + rad), thatXR = (that.xPos + rad), thatXL = (that.xPos - rad), thatYT = (that.yPos - rad), thatYB = (that.yPos + rad); console.log(that, (((newXR > thatXL && newXR < thatXR) || (newXL > thatXL && newXL < thatXR)) && ((newYB > thatYT && newYB < thatYB) || (newYT > thatYT && newYT < thatYB)))); return (((newXR > thatXL && newXR < thatXR) || (newXL > thatXL && newXL < thatXR)) && ((newYB > thatYT && newYB < thatYB) || (newYT > thatYT && newYT < thatYB))); }); } $(canvasE).on('click', function (e) { var xPos = e.offsetX, yPos = e.offsetY, isBall = checkBall(xPos, yPos); if (isBall.length === 0) { drawBall(xPos, yPos); } });
});
Canvas experiment 1 - Script Codes
Canvas experiment 1 - Script Codes
Home Page Home
Developer Justin Richardsson
Username hallaathrad
Uploaded August 31, 2022
Rating 3
Size 3,412 Kb
Views 40,480
Do you need developer help for Canvas experiment 1?

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!