Canvas Gears
How do I make an canvas gears?
In progress.. What is a canvas gears? How do you make a canvas gears? This script and codes were developed by Kevin on 27 August 2022, Saturday.
Canvas Gears - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Canvas Gears</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas id="canvas"></canvas> <script src="js/index.js"></script>
</body>
</html>
Canvas Gears - Script Codes CSS Codes
body { height: 100vh; background-color: black; display: flex; justify-content: center; align-items: center;
}
#canvas { height: 500px; width: 500px; border: solid 1px black;
}
Canvas Gears - Script Codes JS Codes
function draw() { var canvas = document.getElementById("canvas"); canvas.height = 500; canvas.width = 500; if (canvas.getContext) { var ctx = canvas.getContext("2d"); var gearColor = '#b85d33'; var bgColor = ctx.createRadialGradient(canvas.width / 2, canvas.height / 2, 0, canvas.width / 2, canvas.height / 2, canvas.width); bgColor.addColorStop(0, '#000d1a'); bgColor.addColorStop(1, '#00001a'); ctx.fillStyle = bgColor; ctx.fillRect(0, 0, canvas.width, canvas.height); var boltColor = '#7c3722'; var centerColor = '#b85d33'; ctx.strokeStyle = gearColor; var arcA = []; function ArcCreator(x, y, r, angle, speed) { this.x = x; this.y = y; this.r = r; this.angle = angle; this.speed = speed; } function getMainArcs(x, y, radius, angle, speed, teethCount, teethSizeDivider, bars, color1) { var newArc = new ArcCreator(x, y, radius, Math.PI * 2, speed); newArc.color1 = color1; newArc.innerArcs = []; for (var i = 0; i < Math.PI * 2; i += Math.PI / (teethCount / 2)) { var point = [x + Math.cos(i) * radius, y + Math.sin(i) * radius]; var innerArc = new ArcCreator(point[0], point[1], radius / teethSizeDivider, i); newArc.innerArcs.push(innerArc); } newArc.bars = []; for (var j = 0; j < Math.PI*2; j+= (Math.PI*2)/bars){ var bar = { x: x+Math.cos(j)*(radius*.8), y: y + Math.sin(j) * (radius*.8), angle: j }; newArc.bars.push(bar); } arcA.push(newArc); } console.log(arcA); function animate() { ctx.fillStyle = bgColor; ctx.fillRect(0, 0, canvas.width, canvas.height); for (var i = 0; i < arcA.length; i++) { ctx.strokeStyle = arcA[i].color1; ctx.fillStyle = arcA[i].color1; ctx.beginPath(); ctx.arc(arcA[i].x, arcA[i].y, arcA[i].r, 0, Math.PI * 2); ctx.fill(); ctx.beginPath(); ctx.fillStyle = bgColor; ctx.arc(arcA[i].x, arcA[i].y, arcA[i].r * .8, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = arcA[i].color1; for(var k = 0; k < arcA[i].bars.length; k++){ ctx.beginPath(); ctx.moveTo(arcA[i].x, arcA[i].y); ctx.lineTo(arcA[i].bars[k].x, arcA[i].bars[k].y); ctx.lineWidth = arcA[i].r/8; ctx.stroke(); arcA[i].bars[k].angle+= arcA[i].speed; arcA[i].bars[k].x = arcA[i].x + Math.cos(arcA[i].bars[k].angle) * (arcA[i].r*.8) arcA[i].bars[k].y = arcA[i].y + Math.sin(arcA[i].bars[k].angle) * (arcA[i].r*.8) } for (var j = 0; j < arcA[i].innerArcs.length; j++) { ctx.beginPath(); ctx.arc(arcA[i].innerArcs[j].x, arcA[i].innerArcs[j].y, arcA[i].innerArcs[j].r, 0, Math.PI * 2); ctx.fill(); arcA[i].innerArcs[j].angle += arcA[i].speed; arcA[i].innerArcs[j].x = arcA[i].x + Math.cos(arcA[i].innerArcs[j].angle) * arcA[i].r; arcA[i].innerArcs[j].y = arcA[i].y + Math.sin(arcA[i].innerArcs[j].angle) * arcA[i].r; } ctx.beginPath(); ctx.fillStyle = centerColor; ctx.arc(arcA[i].x, arcA[i].y, arcA[i].r * .4, 0, Math.PI * 2); ctx.fill(); ctx.fillStyle = arcA[i].color1; ctx.fillStyle = boltColor; ctx.beginPath(); ctx.arc(arcA[i].x, arcA[i].y, arcA[i].r * .1, 0, Math.PI * 2); ctx.fill(); } requestAnimationFrame(animate); } animate(); //X, Y, radius, angle(should always be Math.PI*2 for a full circle), speed, teethCount, teethSizeDivider (based on total radius), bar count, color getMainArcs(150, 120, 100, Math.PI * 2, .01, 20, 10, 5, '#b85d33'); getMainArcs(150, 120, 50, Math.PI * 2, -.015, 20, 10, 5, '#7c3722'); getMainArcs(343, 201, 100, Math.PI * 2, -.01, 20, 10,3, '#7c3722'); getMainArcs(225, 307, 50, Math.PI * 2, .02, 10, 6, 2, '#b85d33'); getMainArcs(408, 346, 50, Math.PI * 2, .02, 10, 6, 8, '#b85d33'); getMainArcs(290, 452, 100, Math.PI * 2, -.01, 20, 10, 4, '#7c3722'); getMainArcs(225, 307, 25, Math.PI * 2, .04, 10, 6, 2, '#7c3722'); getMainArcs(61, 434, 120, Math.PI * 2, .01, 20, 12, 10, '#b85d33'); getMainArcs(543, 36, 150, Math.PI * 2, (2/3)/100, 30, 16, 10, '#b85d33'); }
}
draw();
Developer | Kevin |
Username | KevinBruland |
Uploaded | August 27, 2022 |
Rating | 3 |
Size | 2,800 Kb |
Views | 18,216 |
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 |
Markdown preview | 3,250 Kb |
Experimenting1 | 1,737 Kb |
A Pen by Kevin | 3,135 Kb |
CSS Transform Sphere | 1,995 Kb |
Local Weather | 3,638 Kb |
Canvas Mouse Position Radial Gradient | 2,031 Kb |
CSS Zen Garden Template | 8,867 Kb |
Memory | 4,680 Kb |
Canvas Spiral Loader | 2,359 Kb |
Calculator | 3,704 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 |
404 Page | Saransh | 2,666 Kb |
Particle Motion trajectories | Sniejadlik | 5,899 Kb |
Weather App | OmranAbazid | 2,596 Kb |
Simple Weather App | Cmwebby | 0 Kb |
Pruebas de d3.js | Juanmanuelcarnerero | 2,485 Kb |
Sticky footer testing | 75th | 1,649 Kb |
CSS Grid Test | Ajaykarwal | 2,377 Kb |
SCSS Simple Animated Drop-In | Danwarfel | 2,175 Kb |
CSS3 keyframe onload animation. | Samueljseay | 1,706 Kb |
Resume | Rottingroom | 5,483 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!