Gears

Developer
Size
3,278 Kb
Views
26,312

How do I make an gears?

It's a cool animation... My Website. What is a gears? How do you make a gears? This script and codes were developed by Ryan Allred on 12 September 2022, Monday.

Gears Previews

Gears - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Gears</title> <script src="https://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ body { background: #444; text-align: center;
}
#gears { -webkit-filter: drop-shadow(0px 0px 2px black); // future: -moz-filter: drop-shadow(0px 0px 2px black);
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <canvas id="gears"></canvas>
<!--Sorry, it's not retina--> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>

Gears - Script Codes CSS Codes

body { background: #444; text-align: center;
}
#gears { -webkit-filter: drop-shadow(0px 0px 2px black); // future: -moz-filter: drop-shadow(0px 0px 2px black);
}

Gears - Script Codes JS Codes

window.requestAnimFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function( callback ){ window.setTimeout(callback, 1000 / 60); };
})();
(function(){ $(function(){ gears.setup(); }); var global = {}; var gears = { setup:function(){ this.canvas = $('#gears')[0]; this.canvas.width = 480; this.canvas.height = 480; this.cxt = this.canvas.getContext('2d'); global.whiteGradient = this.cxt.createLinearGradient(0,0,0,this.canvas.height); global.whiteGradient.addColorStop("0","white"); global.whiteGradient.addColorStop("1","rgba(255,255,255,.5)"); global.toHue = Math.round(Math.random()*9)*20; global.hue = global.toHue; global.colorGradient = this.cxt.createLinearGradient(0,0,0,this.canvas.height); global.colorGradient.addColorStop("0","hsla("+global.hue+",100%,30%,1)"); global.colorGradient.addColorStop("0.5","hsla("+global.hue+",100%,50%,1)"); global.colorGradient.addColorStop("1","hsla("+global.hue+",100%,10%,1)"); this.cxt.lineWidth = 16; this.gears = [gear(128,this.canvas), gear(96,this.canvas), gear(64,this.canvas), gear(32,this.canvas)]; this.draw(); window.setTimeout(function changeHue(){ global.toHue = Math.round(Math.random()*9)*20; window.setTimeout(changeHue, Math.round(Math.random()*1000+10000)); }, Math.round(Math.random()*1000+10000)); }, draw:function(){ this.cxt.clearRect(0,0,this.canvas.width,this.canvas.height); this.cxt.lineWidth = 16; for(var i = 0, size = this.gears.length; i<size; ++i) { this.gears[i].draw(this.cxt, this.canvas); } this.adjust2Hue(); window.requestAnimFrame(function(){ gears.draw(); }); }, adjust2Hue:function(){ if (global.hue === global.toHue) return; if (Math.abs(global.hue - global.toHue) > Math.abs(global.hue - global.toHue + 360)) global.toHue += 360 if (Math.abs(global.hue-global.toHue) < 1.) { global.hue = global.toHue; } else { global.hue += (global.toHue-global.hue)/100; global.colorGradient = this.cxt.createLinearGradient(0,0,0,this.canvas.height); global.colorGradient.addColorStop("0","hsla("+global.hue+",100%,30%,1)"); global.colorGradient.addColorStop("0.5","hsla("+global.hue+",100%,50%,.8)"); global.colorGradient.addColorStop("1","hsla("+global.hue+",100%,50%,0)"); } } }; var gear = function(radius,canvas){ return { init:function(){ var cxt = canvas.getContext('2d'); this.radius = radius; this.angle=Math.random() * Math.PI * 2; this.newSpeedValue = 0; this.newSpeed(); this.speed = Math.round(Math.random())==1?-0.1:0.1; this.timerInit = 50; this.timer = this.timerInit; this.last = this.radius == 128; this.bars = []; this.numBars = 1; do { this.numBars++; if (this.numBars > 5) break; } while(Math.round(Math.random()) == 0 || this.numBars < 2); this.newBars = []; this.newBars.length = this.numBars; this.makeNewBars(); for(var i = 0; i < this.numBars-1; i++){ this.bars[i] = this.newBars[i]; } this.hue = this.toHue; if (this.last) { this.newSpeedValue = .01; this.newBars = this.bars = [Math.PI]; } return this; }, draw:function(cxt, canvas){ if (!this.last) { this.timer -=1; if (this.timer == 0) { this.timer = this.timerInit; this.newSpeed(); this.makeNewBars(); } } if (this.last) { this.gradient = global.whiteGradient; this.newSpeedValue = .01; } else { this.gradient = global.colorGradient; } this.adjust(); this.angle+=this.speed; var sum = 0; cxt.save(); for(var i = 0; i < this.numBars; i++) { cxt.beginPath(); cxt.strokeStyle = this.gradient; cxt.arc( canvas.width/2, canvas.height/2, this.radius, this.angle - sum - this.bars[i]*.9, this.angle - sum - this.bars[i]*.1 ); cxt.stroke(); sum += this.bars[i]; } cxt.restore(); }, newSpeed:function(){ var reverse = true; if (!this.last) { reverse = !!Math.round(Math.random()); } this.newSpeedValue = (reverse?-1:1) * Math.random()/10 + .01; }, adjust:function(){ if (Math.abs(this.speed-this.newSpeedValue) < .001) { this.speed = this.newSpeedValue; } else { this.speed += (this.newSpeedValue-this.speed)/10; } for(var i = 0; i < this.numBars; i++) { if (Math.abs(this.bars[i]-this.newBars[i]) < .001) { this.bars[i] = this.newBars[i]; } else { this.bars[i] += (this.newBars[i]-this.bars[i])/100; } } }, makeNewBars:function(){ var remaining = Math.PI*2; for(var i = 0; i < this.numBars-1; i++){ var width = Math.random()*remaining; remaining -= width; this.newBars[i] = width; } this.newBars[this.numBars-1] = remaining; } }.init(); }
})()
Gears - Script Codes
Gears - Script Codes
Home Page Home
Developer Ryan Allred
Username Synvox
Uploaded September 12, 2022
Rating 4
Size 3,278 Kb
Views 26,312
Do you need developer help for Gears?

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!

Ryan Allred (Synvox) Script Codes
Create amazing captions 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!