Canvas experiment 1
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 - 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); } });
});
Developer | Justin Richardsson |
Username | hallaathrad |
Uploaded | August 31, 2022 |
Rating | 3 |
Size | 3,412 Kb |
Views | 40,480 |
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 |
Tribute to Peter Singer | 2,090 Kb |
Zen quote generator | 8,480 Kb |
Portfolio | 9,868 Kb |
Canvas experiment 3 | 3,609 Kb |
Calculator | 4,493 Kb |
Canvas experiment 2 | 2,903 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 |
Smoke Shader - Frame Buffer | Omarshe7ta | 2,672 Kb |
Roman Numerical Converter | Vhall_io | 2,102 Kb |
Simple Weather App | Cmwebby | 0 Kb |
NeeilTimer | Neeilan | 2,836 Kb |
Sticky div | Kaslab | 2,225 Kb |
A Pen by Rob Levin | Roblevin | 2,787 Kb |
TinFoil Boats | Chandralil | 4,577 Kb |
Awesome Full Page Menu Nav | Ey_intuitive | 4,194 Kb |
Slide out Menu | Rbiggs | 4,936 Kb |
Parallax with only CSS | Thulioph | 2,297 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!