Skip to main content
AmigoFish

Coding Challenge 185: Unfolding Fractals

From The Coding Train ยท ยท 31 min

The player loads from YouTube only when you click. It uses YouTube's privacy-enhanced mode.

If the video does not play, the owner may have turned off embedding. Watch it on YouTube instead.

Watch on YouTube

Not rated yet

Description

25% off The Nature of Code book with code CHOOCHOO at https://natureofcode.com (comes with exclusive sticker+bookmark).

The Dragon Curve fractal is created by repeatedly folding a strip of paper in half, then unfolding it to form a curve. In this challenge, I attempt to code an animation of the Dragon Curve forming with p5.js in JavaScript. Code: https://thecodingtrain.com/challenges/185-dragon-curve

๐Ÿš€ Watch this video ad-free on Nebula https://nebula.tv/videos/codingtrain-coding-challenge-184-dragon-curve

p5.js Web Editor Sketches: ๐Ÿ•น๏ธ Dragon curve animation: https://editor.p5js.org/codingtrain/sketches/LXDsoCSZs ๐Ÿ•น๏ธ Dragon curve color variation: https://editor.p5js.org/codingtrain/sketches/7nNd-f7iY ๐Ÿ•น๏ธ Dragon curve noise variation: https://editor.p5js.org/codingtrain/sketches/7r7ZIE4dc

๐ŸŽฅ Previous: https://youtu.be/dJNFPv9Mj-Y?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH ๐ŸŽฅ All: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH

References: ๐Ÿ“• The Nature of Code: https://natureofcode.com/ ๐Ÿ›’ Nature of Code shop: https://store.natureofcode.com/products/the-nature-of-code ๐Ÿ”— Dragon Curve: https://en.wikipedia.org/wiki/Dragon_curve ๐Ÿ”— concat() function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat

Videos: ๐ŸŽฅ https://youtu.be/UBuPWdSbyf8 ๐ŸŽฅ https://www.youtube.com/watch?v=wCyC-K_PnRY

Related Coding Challenges: ๐Ÿš‚ https://youtu.be/0jjeOYMjmDU ๐Ÿš‚ https://youtu.be/E1B4UoSQMFw ๐Ÿš‚ https://youtu.be/jPsZwrV9ld0 ๐Ÿš‚ https://youtu.be/i-k04yzfMpw ๐Ÿš‚ https://youtu.be/dSK-MW-zuAc

Timestamps: 00:00 Introduction 00:36 The Nature of Code book 01:43 Explain algorithm 03:38 Start coding 05:05 Write rotate function 07:05 Rotate all the segments 11:30 We have the dragon curve! 12:00 Add animation 16:31 Add the starting positions for a and b 21:43 Scale the lines 24:08 Add a nextGeneration() function 25:16 The reduction ratio 26:44 Target zoom 28:57 Challenge complete! 29:57 What can you do? 30:25 Outro

Editing by Mathieu Blanchette Animations by Jason Heglund Music from Epidemic Sound

๐Ÿš‚ Website: https://thecodingtrain.com/ ๐Ÿ‘พ Share Your Creation! https://thecodingtrain.com/guides/passenger-showcase-guide ๐Ÿšฉ Suggest Topics: https://github.com/CodingTrain/Suggestion-Box ๐Ÿ’ก GitHub: https://github.com/CodingTrain ๐Ÿ’ฌ Discord: https://thecodingtrain.com/discord ๐Ÿ’– Membership: http://youtube.com/thecodingtrain/join ๐Ÿ›’ Store: https://standard.tv/codingtrain ๐Ÿ–‹๏ธ Twitter: https://twitter.com/thecodingtrain ๐Ÿ“ธ Instagram: https://www.instagram.com/the.coding.train/

๐ŸŽฅ https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH ๐ŸŽฅ https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA

๐Ÿ”— p5.js: https://p5js.org ๐Ÿ”— p5.js Web Editor: https://editor.p5js.org/ ๐Ÿ”— Processing: https://processing.org

๐Ÿ“„ Code of Conduct: https://github.com/CodingTrain/Code-of-Conduct

This description was auto-generated. If you see a problem, please open an issue: https://github.com/CodingTrain/thecodingtrain.com/issues/new

#fractals #dragoncurve #natureofcode #p5js #javascript

Back to The Coding Train ยท Report a problem