Spirograph
How do I make an spirograph?
My entry for CodePen rodeo-006.. What is a spirograph? How do you make a spirograph? This script and codes were developed by Francesco Trillini on 01 September 2022, Thursday.
Spirograph - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Spirograph</title> <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 { margin: 0px; overflow: hidden;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <body></body> <script src="js/index.js"></script>
</body>
</html>
Spirograph - Script Codes CSS Codes
body { margin: 0px; overflow: hidden;
}
Spirograph - Script Codes JS Codes
/* * Copyright MIT © <2013> <Francesco Trillini> * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
var self = window;
(function(self) { var canvas, context, particles = [], explode = true, FPS = 60; /* * Init. */ function init() { var body = document.querySelector('body'); canvas = document.createElement('canvas'); canvas.width = innerWidth; canvas.height = innerHeight; canvas.style.position = 'absolute'; canvas.style.top = 0; canvas.style.bottom = 0; canvas.style.left = 0; canvas.style.right = 0; canvas.style.background = '-webkit-radial-gradient(rgb(252, 252, 240), rgb(203, 192, 180))'; canvas.style.background = '-moz-radial-gradient(rgb(252, 252, 240), rgb(203, 192, 180))'; canvas.style.background = '-ms-radial-gradient(rgb(252, 252, 240), rgb(203, 192, 180))'; canvas.style.background = '-o-radial-gradient(rgb(252, 252, 240), rgb(203, 192, 180))'; canvas.style.background = 'radial-gradient(rgb(252, 252, 240), rgb(203, 192, 180))'; body.appendChild(canvas); // Browser supports canvas? if(!!(capable)) { context = canvas.getContext('2d'); window.onresize = onResize; createParticles(); } else { console.error("Sorry, your browser doesn't support canvas."); } } /* * Check if browser supports canvas element. */ function capable() { return canvas.getContext && canvas.getContext('2d'); } /* * On resize window event. */ function onResize() { canvas.width = window.innerWidth; canvas.height = window.innerHeight; } /* * Create particles. */ function createParticles() { for(var quantity = 0, len = 200; quantity < len; quantity++) { var x, y, steps; steps = Math.PI * 2 * quantity / len; x = canvas.width * 0.5 + 200 * Math.cos(steps); y = canvas.height * 0.5 + 200 * Math.sin(steps); particles.push({ x: x, y: y, lineX: x, lineY: y, centerX: canvas.width * 0.5, centerY: canvas.height * 0.5, originalX: x, originalY: y, scale: 1, radius: 3, minRadius: 3, maxRadius: 9, orbit: 100, angle: 0, speed: 0.05, steps: steps }); } loop(); } /* * Loop logic. */ function loop() { clear(); update(); render(); requestAnimFrame(loop); } /* * Clear the whole screen. */ function clear() { context.clearRect(0, 0, canvas.width, canvas.height); } /* * Update the particles. */ function update() { var towards = { x: Math.round(canvas.width * 0.5), y: Math.round(canvas.height * 0.5) }; [].forEach.call(particles, function(particle, index) { particle.x = particle.centerX + Math.cos(particle.angle + index) * particle.orbit; particle.y = particle.centerY + Math.sin(particle.angle + index) * particle.orbit; particle.originalX += (towards.x + 200 * Math.cos(particle.steps) - particle.originalX) * 0.05; particle.originalY += (towards.y + 200 * Math.sin(particle.steps) - particle.originalY) * 0.05; particle.lineX += (towards.x + 200 * Math.cos(particle.steps) - particle.lineX) * 0.05; particle.lineY += (towards.y + 200 * Math.sin(particle.steps) - particle.lineY) * 0.05; particle.scale = 1 + Math.sin(particle.angle) * 5; particle.angle += particle.speed; // Implosion if(!explode) { particle.centerX += (towards.x - particle.centerX) * 0.05; particle.centerY += (towards.y - particle.centerY) * 0.05; particle.radius += (particle.maxRadius - particle.radius) * 0.05; if(Math.round(particle.centerX) === towards.x && Math.round(particle.centerY) === towards.y) explode = true; } // Explosion if(explode) { particle.centerX += (particle.originalX - particle.centerX) * 0.05; particle.centerY += (particle.originalY - particle.centerY) * 0.05; particle.radius += (particle.minRadius - particle.radius) * 0.05; if(Math.round(particle.centerX) === Math.round(particle.originalX) && Math.round(particle.centerY) === Math.round(particle.originalY)) explode = false; } }); } /* * Render the particles. */ function render() { [].forEach.call(particles, function(particle, index) { context.save(); context.globalAlpha = 0.5; context.strokeStyle = 'rgb(84, 64, 47)'; context.lineWidth = 1; context.beginPath(); context.moveTo(particle.lineX, particle.lineY); context.lineTo(particle.x, particle.y); context.stroke(); context.restore(); }); [].forEach.call(particles, function(particle, index) { context.save(); context.translate(particle.x, particle.y); context.scale(particle.scale, particle.scale); context.globalCompositeOperation = 'lighter'; context.globalAlpha = 1; context.fillStyle = 'rgb(84, 64, 47)'; context.beginPath(); context.arc(0, 0, particle.radius, 0, Math.PI * 2); context.fill(); context.restore(); }); } /* * Request new frame by Paul Irish. * 60 FPS. */ window.requestAnimFrame = (function() { return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / FPS); }; })(); window.addEventListener ? window.addEventListener('load', init, false) : window.onload = init;
})(self);
Developer | Francesco Trillini |
Username | Francext |
Uploaded | September 01, 2022 |
Rating | 4 |
Size | 3,893 Kb |
Views | 105,248 |
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 |
Abstract Audio Visualizer | 8,048 Kb |
Waviness | 4,500 Kb |
Interactive Bezier Doodle | 4,749 Kb |
GooglePixelate | 4,142 Kb |
Pulsar | 5,686 Kb |
Twitter Unfold Concept | 2,343 Kb |
Spiral | 4,523 Kb |
Molecules | 4,760 Kb |
GoogleForce | 5,247 Kb |
Typo | 4,738 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 |
Monochrome Form | AlienPiglet | 3,096 Kb |
Blog demo to use given styling | Andygirl | 2,412 Kb |
Glowing Pulse Form | Jackrugile | 2,542 Kb |
Dribbble Inspired Registration Form | Lancebush | 2,358 Kb |
Swiftype Lower Third | Zumwalt | 4,796 Kb |
TigerWoods Freecodecamp Page | Baileytj | 2,869 Kb |
Loader | MikitaLisavets | 3,321 Kb |
Tumblr API | Juanv911 | 2,436 Kb |
Improve | Gavra | 1,652 Kb |
Twitch API | Coderpilot | 3,412 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!