Dragon curve
How do I make an dragon curve?
Dragon curve fractal. What is a dragon curve? How do you make a dragon curve? This script and codes were developed by Pimskie on 13 June 2022, Monday.
Dragon curve - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Dragon curve</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <canvas class="canvas canvas-dragon"></canvas> <script src='http://cdnjs.cloudflare.com/ajax/libs/gsap/1.19.0/TweenMax.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Dragon curve - Script Codes CSS Codes
html,
body { width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden; background: #000;
}
Dragon curve - Script Codes JS Codes
const SEGMENT_WIDTH = 5;
const ctx = document.querySelector('canvas').getContext('2d');
const drawSet = (path, x, y, segmentAngle) => { ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); let angle = 0; ctx.beginPath(); ctx.lineWidth = 1; ctx.strokeStyle = '#ff0000'; ctx.moveTo(x, y); path.forEach((turn) => { x -= Math.cos(angle) * SEGMENT_WIDTH; y += Math.sin(angle) * SEGMENT_WIDTH; ctx.lineTo(x, y); angle += segmentAngle * turn; }); ctx.stroke(); ctx.closePath();
}
const getPath = (currentPath, currentDepth, maxDepth) => { /* each iteration is formed by taking the previous iteration, adding an R at the end (1), and then taking the original iteration again (2), flipping it retrograde (3), swapping each letter (4) adding the result after the R. https://en.wikipedia.org/wiki/Dragon_curve#.5BUn.5DFolding_the_Dragon */ currentPath = currentPath // (1) adding an R at the end .concat([-1].concat( // (2) taking the original iteration again currentPath .slice() // (3) flipping it retrograde .reverse() // (4) swapping each letter .map((turn) => turn * -1) )); return currentPath;
}
let tween;
const reset = () => { ctx.canvas.width = window.innerWidth; ctx.canvas.height = window.innerHeight; let path = []; let depth = 12; while (depth--) { path = getPath(path); } const anim = { angle: -Math.PI * 0.5 }; TweenMax.killAll(); tween = TweenMax.to(anim, 5, { angle: Math.PI * 0.5, yoyo: true, repeat: -1, repeatDelay: 2, ease: Sine.easeInOut, onUpdate: () => { drawSet( path, window.innerWidth >> 1, window.innerHeight >> 1, anim.angle ); } });
}
window.addEventListener('resize', reset);
reset();
Developer | Pimskie |
Username | pimskie |
Uploaded | June 13, 2022 |
Rating | 4 |
Size | 2,662 Kb |
Views | 76,912 |
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 |
Rainbow particles | 3,673 Kb |
Particles Clifford attractor | 3,448 Kb |
Duplicate geometry | 4,190 Kb |
Aizawa Attractor | 3,609 Kb |
Circles pattern | 3,342 Kb |
Tree mirror | 3,472 Kb |
A Pen by pimskie | 3,699 Kb |
A Pen by pimskie | 2,486 Kb |
Glitching image - USA style | 4,733 Kb |
Exploding hamburger - and more | 7,785 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 |
LDE old privacy page | Jasonangle | 2,339 Kb |
MAD9013 - Float Images with Content | Mad-d | 2,220 Kb |
Portfolio Landing Page | FDfranklin | 3,585 Kb |
Login-ng-modal | Heedoo | 3,566 Kb |
Under construction | GhostRider | 1,642 Kb |
Using Flickr API | MoyArt | 6,761 Kb |
Mega menu | DimaZubkov | 5,066 Kb |
JS Countdown Timer | Ayoungh | 2,435 Kb |
SCSS Unit Conversion | Jakob-e | 8,210 Kb |
Responsive Pricing Table | Jeremycaris | 2,690 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!