Coding Challenge #2: Menger Sponge Fractal

  Рет қаралды 307,372

The Coding Train

The Coding Train

Күн бұрын

In this coding challenge, I attempt to code the Menger Sponge (fractals) using Processing. Code: thecodingtrain.com/challenges...
🕹️ p5.js Web Editor Sketch: editor.p5js.org/codingtrain/s...
🎥 Previous video: • Coding Challenge 1: St...
🎥 Next video: • Coding Challenge #3: T...
🎥 All videos: • Coding Challenges
References:
🌐 Menger Sponge on Wikipedia: en.wikipedia.org/wiki/Menger_...
🇵 P3D Tutorial: processing.org/tutorials/p3d/
🇵 ArrayList in Processing: processing.org/reference/Arra...
Videos:
🎥 Fractals in Processing: • 8: Fractals - The Natu...
🔴 Coding Train Live 31: • Coding Train Live 31: ...
Related Coding Challenges:
🚂 #18 3D Fractal Trees: • Coding Challenge #18: ...
🚂 #123 Chaos Game: • Coding Challenge #123:...
🚂 #126 Toothpicks: • Coding Challenge #126:...
🚂 #129 Koch Fractal Snowflake: • Coding Challenge #129:...
🚂 #168 The Mandelbulb: • Coding Challenge 168: ...
Timestamps:
0:00 Welcome to a 10 minute Coding Challenge!
0:26 Quick math about the Menger Sponge
1:02 Code! Drawing a 3D box in Processing
2:14 Creating a Box class
3:36 Use a Box object instead of the hardcoded box
4:02 Chopping up one Box into multiple ones
6:53 Modeling the Menger Sponge as an ArrayList of Boxes
7:41 Generating the next iteration on mouse click
9:47 Bonus time! Adding 2 more minutes 😜
10:03 How to determine which boxes need to be removed?
10:48 Code! Removing the extra boxes
12:12 Enhancing the visuals
13:32 Done! The Menger Sponge in Processing
Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound
🚂 Website: thecodingtrain.com/
👾 Share Your Creation! thecodingtrain.com/guides/pas...
🚩 Suggest Topics: github.com/CodingTrain/Sugges...
💡 GitHub: github.com/CodingTrain
💬 Discord: / discord
💖 Membership: kzfaq.infojoin
🛒 Store: standard.tv/codingtrain
🖋️ Twitter: / thecodingtrain
📸 Instagram: / the.coding.train
🎥 Coding Challenges: • Coding Challenges
🎥 Intro to Programming: • Start learning here!
🔗 p5.js: p5js.org
🔗 p5.js Web Editor: editor.p5js.org/
🔗 Processing: processing.org
📄 Code of Conduct: github.com/CodingTrain/Code-o...
This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecod...
#fractal #3d #processing

Пікірлер: 387
@OrchidAlloy
@OrchidAlloy 8 жыл бұрын
Considering you're also taking the time to explain everything to the audience, you should start by giving yourself 15 minutes instead of only 10. It's fair!
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
heh, good point!
@Acecool
@Acecool 4 жыл бұрын
The biggest part is design; coding doesn't take long at all when you have a plan.
@__europa
@__europa Жыл бұрын
@Acecool the point of this challenge is to make spmething up in under 10 minutes, not to get everything designed prepared beforehand.
@jadielbett237
@jadielbett237 2 жыл бұрын
Can we just take a moment and acknowledge that with 10 seconds to go in bonus time, he managed to come up with an outstanding fractal completely by accident, the inverse Menger Sponge Fractal. Now that's nature!
@AlxM96
@AlxM96 7 жыл бұрын
Who on Earth would ever dislike such a masterpiece of a video?
@11itech11
@11itech11 5 жыл бұрын
Yeah a masterpiece.
@johnlemon273
@johnlemon273 4 жыл бұрын
those who hate to break sweat to Math
@dr.dank5769
@dr.dank5769 4 жыл бұрын
it's non-human
@condor1234
@condor1234 2 жыл бұрын
Someone who spend 15hrs, thinking of the logic, writing the code and still ends up failing. And after that coming into youtube just to drop in this video to let them see someone did it + explanation in less than 15mins. 😂😂😂😂
@theonecallednick
@theonecallednick 2 жыл бұрын
Probably it was mediocore, no offense
@cimmik
@cimmik 8 жыл бұрын
What I did in order to learn as much as possible from this video, was trying to make it myself before I saw how Daniel would do it. Then I compare my approach to Daniel’s approach. This way, I challenge myself, and I will find alternative ways to solve problems.
@noelearlwatson2724
@noelearlwatson2724 8 жыл бұрын
Nice
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
love that!
@SaintPepsiSanCoca
@SaintPepsiSanCoca 8 жыл бұрын
Wow that is a very good approach, I think i'll do it this way as well! :D
@spoderman15
@spoderman15 7 жыл бұрын
Lol this is how I do all my school work problems (the ones that have solutions anyway)
@2001herne
@2001herne 5 жыл бұрын
I'm not quite confident enough in my abilities to do this - however, I work in python, not java/processing - so I need to figure out how to implement the logic in python, which still takes a bit of thinking.
@johnvonhorn2942
@johnvonhorn2942 8 жыл бұрын
If this man did these challenges at parties women would want him. I find him to be downright heroic.
@pmAdministrator
@pmAdministrator 7 жыл бұрын
Whoa... you dirty....
@chrisj4288
@chrisj4288 7 жыл бұрын
I mean, I'm not sure if dirty is quite the right word here... but it's definitely inappropriate...
@nickjimenez3250
@nickjimenez3250 7 жыл бұрын
Christopher Johns - What's dirty about it? ._.
@martynBVT
@martynBVT Жыл бұрын
maybe all the intellectual, comp sci loving and math loving women XD
@Eddygeek18
@Eddygeek18 7 жыл бұрын
Was coding along with it, was doing little bits myself and coppied a most of it from yours and it worked perfect. I know other languages but im reasonably new to java and js. Watching your videos is a great way to learn. Thank you and cant wait to keep watching :)
@grandosprey6450
@grandosprey6450 7 жыл бұрын
Always love watching you do challenges. It truly shows the magic of writing code. I hope I can one day be as impressive.
@shapkofil4708
@shapkofil4708 3 жыл бұрын
11:21 Pressure truly blinds men beyond multiplication
@DThorn619
@DThorn619 8 жыл бұрын
Now these are some really interesting videos. Really puts your other coding tutorials into perspective because you can clearly see parts of them being used throughout your video. Great supplemental material!
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Asad Mirza Thanks for this feedback, glad to hear!
@lumigg2556
@lumigg2556 7 жыл бұрын
my brain just exploded :D
@Xeronimo74
@Xeronimo74 8 жыл бұрын
these 10 min challenges are really amazing, educational and inspiring!
@predicate
@predicate 6 жыл бұрын
[insert clever joke about how the content of this video relates to my profile picture]
@mr.rabbit5642
@mr.rabbit5642 4 жыл бұрын
Nice clever joke ;D
@xavierbradford5528
@xavierbradford5528 4 жыл бұрын
Wrong coding challenge lol
@BloodyScythe666
@BloodyScythe666 7 жыл бұрын
I love these coding challenge videos. would really enjoy more of them.
@bravodude6175
@bravodude6175 Жыл бұрын
Even if I don’t know the math behind your processes, I’m still learning valuable information on how you approach these problems and think them out! I appreciate all the content you put out!
@abdulbakiaybakan8836
@abdulbakiaybakan8836 5 жыл бұрын
I wish I had that much energy and intelligence. You think and find solution so fast. Just Amazing!!! (I wonder who dislikes this video)
@liwaiyip1769
@liwaiyip1769 7 жыл бұрын
Your videos are so educational and interesting, please keep making more of these :D
@jacosh3924
@jacosh3924 6 жыл бұрын
Checking if the combined absolute value was less than 0 is a genius way to work this out centres. Thanks for the great video!!
@harrys4698
@harrys4698 6 жыл бұрын
I just got an ad with you in it on your own video, and I'm glad youtube is now this meta
@Moviechopper200
@Moviechopper200 2 жыл бұрын
Hey! you are amazing man. One of the best teachers I've ever seen.
@trekhopton
@trekhopton 8 жыл бұрын
I'm absolutely loving these 10 min episodes! Keep it up man!
@trekhopton
@trekhopton 8 жыл бұрын
+Trekobius I'm learning a lot and I really enjoy your teaching style
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Trekobius thank you so much, glad to hear!
@palmweaver
@palmweaver 5 жыл бұрын
Once again, a very good demonstration.
@frankakn_7448
@frankakn_7448 7 жыл бұрын
You deserve way more subscribers
@wendyzhou7618
@wendyzhou7618 2 жыл бұрын
thank you for sharing! love this type of challenge
@ShawnTowne
@ShawnTowne 8 жыл бұрын
Awesome! Loving your 10 min coding projects... this should be a tv show 😉
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Shawn Towne thanks so much!
@valor36az
@valor36az 3 жыл бұрын
Thank you so much for teaching us I added peasy cam, I will continue with these excellent tutorials
@crankyunicorn4423
@crankyunicorn4423 4 жыл бұрын
the if(sum>1) is so sweet I haven't thought of that before and is a thing of beauty
@eddy911
@eddy911 3 жыл бұрын
coding train is my life train since i was 7 years old...i love the challenges
@rajuns5288
@rajuns5288 4 жыл бұрын
Dude HOW are you so good at programming it’s just incredible
@ArnoldsKtm
@ArnoldsKtm 6 жыл бұрын
That looks awesome. That xyz sum was a neat idea.
@informationera4761
@informationera4761 5 жыл бұрын
Your the BlackPink in Programming, you are a true artist.
@owenchetty64
@owenchetty64 7 жыл бұрын
That's so cool!!
@zansaviogamer007
@zansaviogamer007 7 жыл бұрын
You're awesome dude.
@thiagovalentin688
@thiagovalentin688 4 жыл бұрын
Well that was the best coding challenge I've seen someone going through - that was pretty cool! Now I am trying to get my Menger Sponge Level 2 done in Origami hehe =)
@Charlesbabbage2209
@Charlesbabbage2209 7 жыл бұрын
I think my brain just liquefied and drained out my ear. I've got my work cut out for me for the next couple of years. You are the man, Prof Shiffman!
@CarlFurrow
@CarlFurrow 7 жыл бұрын
That was great!
@brunomello7499
@brunomello7499 7 жыл бұрын
You my friend, are a genius
@lilHoodRD
@lilHoodRD 7 жыл бұрын
Hey Mate, That was awesome!
@vincentruben
@vincentruben 4 жыл бұрын
The inverse looked really good!
@Smomid
@Smomid 4 жыл бұрын
Dude, you are a programming god.
@tw7522
@tw7522 6 жыл бұрын
Great stuff!
@shoaibmirza3082
@shoaibmirza3082 8 жыл бұрын
awesome Dan !
@rahulgeorge2409
@rahulgeorge2409 6 жыл бұрын
Amazing work!! Thanks a lot @Daniel :D
@bishalgupta49
@bishalgupta49 6 жыл бұрын
U r a genius man .. i love your coding skills .. hope to be a coder like you .. 😄
@peterv6i
@peterv6i 6 жыл бұрын
Awesome :) nice!
@feyzullaharas9334
@feyzullaharas9334 7 жыл бұрын
insane in the membrane this is how pupil want to learn coding ++
@sweethomes674
@sweethomes674 Жыл бұрын
Excellent 😊
@Richard_is_cool
@Richard_is_cool 7 жыл бұрын
Loved it.
@quintopia
@quintopia 8 жыл бұрын
the sum thing is exactly what i was thinking to do. impressed you thought of it on the fly while talking.
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
thank you!
@MrCamoga
@MrCamoga 8 жыл бұрын
saaame :)
@StevesMakerspace
@StevesMakerspace 3 жыл бұрын
That was intense.
@DanielKierkegaardAndersen
@DanielKierkegaardAndersen 8 жыл бұрын
You are indeed awesome!
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Daniel Kierkegaard Andersen thank you!
@AbhiKumar-fb2zd
@AbhiKumar-fb2zd 2 жыл бұрын
This still looks like a lot of learning in 2022.
@tusharmaurya1668
@tusharmaurya1668 7 жыл бұрын
That 10 minutes, always went off!
@6san6sei6
@6san6sei6 8 жыл бұрын
so amazing!
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+6san6sei6 thank you!
@mr.mysteriousyt6118
@mr.mysteriousyt6118 7 жыл бұрын
this KZfaq channel is the heaven of programmers I'm 15 and so new to programing but I'm still learning.
@TheCodingTrain
@TheCodingTrain 7 жыл бұрын
So glad to hear, thank you for watching!
@alexanderbergkvist9224
@alexanderbergkvist9224 7 жыл бұрын
You are amazing *-*
@TheCodingTrain
@TheCodingTrain 7 жыл бұрын
thank you!
@MerlinZuni
@MerlinZuni 2 жыл бұрын
This was impressive
@XilenceDoGood
@XilenceDoGood 7 жыл бұрын
Following your video, I got a working fractal with a few differences in the rotation, etc. However, you made a comment about making the boxes rainbows, so I went ahead and modified the array with floats for red, green, and blue values (that way they've each got their own randomly assigned color). What I can't figure out is how to pull those values for each box out of the array and push it to the fill command.
@okoiful
@okoiful 8 жыл бұрын
That was amazing dan! :)
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Giorgio Martini thank you!
@Juke172
@Juke172 7 жыл бұрын
mesmerizing
@iancraftsandmines6266
@iancraftsandmines6266 7 жыл бұрын
I can get it to level five (which takes about half a minute to render) and I'm too scared to try level 6. That should theoretically take about 15 minutes). Also I literally hand-typed every single character along with you and got this and then after my wrists were screaming in pain you said the code was in the description. *cri.* But at least it's good practice to type it because I'm learning a lot about Processing from watching you. Thanks for these great videos.
@santoryu8940
@santoryu8940 7 жыл бұрын
man for how long have you been coding
@컨트롤D
@컨트롤D 4 жыл бұрын
wow, amazing sponge fractal! it's very hard to make!
@dsyt985
@dsyt985 6 жыл бұрын
U r a coding god
@leonmueller8710
@leonmueller8710 6 жыл бұрын
I like that u directly say what you think 11:03 is a good example
@CesareVesdani
@CesareVesdani 2 күн бұрын
What is the best and easiest software application for creating a menger sponge?
@themontypython
@themontypython Жыл бұрын
This man, smart smart
@exod4
@exod4 8 жыл бұрын
I like your energy! ! Seems you have a new sub ;)
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+exod4 Thanks so much!
@CharTheDude
@CharTheDude 8 жыл бұрын
+Daniel Shiffman Same here. I love it when someone has this much enthusiasm about something! I hope your channel picks up sometime soon!
@cristianhakansson7443
@cristianhakansson7443 7 жыл бұрын
This is like watching let's plays but with coding, I like it! Not sure if someone already suggested it, but when checking which blocks to exclude i think you could have checked if (x*y*z == 0). The product will be zero if and only if at least one of the terms are :)
@jamiesanders9865
@jamiesanders9865 7 жыл бұрын
But he needed two or more of x,y,z to be == 0
@cristianhakansson7443
@cristianhakansson7443 7 жыл бұрын
Ah, of course :) What I wrote would just leave the corners!
@landsgevaer
@landsgevaer 2 жыл бұрын
x*y + y*z + x*z == 0 would work, although that isn't as simple...
@luhao4337
@luhao4337 7 жыл бұрын
well played
@rosslahive
@rosslahive 7 жыл бұрын
Thanks so Awesome.
@Mike138666
@Mike138666 8 жыл бұрын
wow! so cool!
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Mike138666 Thanks!
@darshgupta6276
@darshgupta6276 2 жыл бұрын
I love that Dan is sacrificing his time to make sure that his audience understands what he's doing. 😁
@jimmycerdaruiz6281
@jimmycerdaruiz6281 7 жыл бұрын
9:29 he says 27 at the same time timer is 27 iluminati confirmed
@scieropia
@scieropia 7 жыл бұрын
gr8 !
@BeastOfTraal
@BeastOfTraal 8 жыл бұрын
An interesting way to create the Menger Sponge is with the chaos game. Mark the 8 points of cube's corner. Pick some random starting point. Randomly pick one of the 8 corners. Mover 1/3 the distance from your current position and that of the random corner. Mark that point. Continue randomly picking corners and moving 1/3 the distance. Do this about 1 million times
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
thanks for the tip!
@rupertrussell1
@rupertrussell1 8 жыл бұрын
Amazing stuff. I will definitely make something with this. I just hope you still have the code handy.
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
Code is here! github.com/CodingRainbow/Rainbow-Code
@josephjohnson4761
@josephjohnson4761 4 ай бұрын
its like a mad scientist
@hvrc0
@hvrc0 7 жыл бұрын
'Some kind of birthing experience' holy shit that killed me
@myselfgroot6721
@myselfgroot6721 6 жыл бұрын
Ont the internet There is nothing i can compare with u are Just Amazing
@kevin._.27
@kevin._.27 6 жыл бұрын
I think you are remaking every generation, when you make a new generation.
@mrping2603
@mrping2603 7 жыл бұрын
this young thing strolls from The Indian Ocean since Rome pounces on my bad problem
@josbex1684
@josbex1684 7 жыл бұрын
muy interesante saludos
@DaleBasye
@DaleBasye 8 жыл бұрын
this was awesome times 3 or 4 !
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Dale Basye thank you!
@giancarlogatti8939
@giancarlogatti8939 7 жыл бұрын
lol i remember it took me forever the first time to do a spaceship that moves in a circle (spaceship follows circle path.
@mulanszechuansauceisthemeaning
@mulanszechuansauceisthemeaning 5 жыл бұрын
ending of the video: goodb
@pantallahueso
@pantallahueso 2 жыл бұрын
I don't know if anyone will see this, but if anyone is following along in Processing for macOS and finding that the box won't render, you might want to try specifying a frameRate(). Apparently something changed in Big Sur that broke P3D without a specified frameRate(). The default is 60.
@typedeaf
@typedeaf 6 жыл бұрын
I BOSD'ed my computer about 4 times, and crashed the browser a dozen times because my triple loop section had x++ on all three, creating an infinite loop. Jeez!
@mannyc6649
@mannyc6649 4 жыл бұрын
10:55 The best way would have been to replace x++ by x+=2, and so on. That's going to skip the zero for all three.
@SerilaBuck
@SerilaBuck 8 жыл бұрын
you should rework it as 15min challenge as you have to account the time you take to explain stuff
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+SerilaBuck I think you are probably right! I would like to see if I can get better / more efficient, but we'll see.
@kid_kulafu_1727
@kid_kulafu_1727 6 жыл бұрын
Omg! Why people dislike this awesomeness! Anyway are you using the macbook pro with touchbar sir?
@nicktucker3387
@nicktucker3387 8 жыл бұрын
I LOVE THESE!!!
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Nick Tucker They are a lot of fun to make! Going to do many more.
@katekay
@katekay 8 жыл бұрын
+Daniel Shiffman you should make more games :) they're really fun to watch being made
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Kate McNamara ok! Will keep this in mind, would love any suggestions for quick and simple ones I might be able to make. Some suggested a "snake" game which is a good one.
@katekay
@katekay 8 жыл бұрын
+Daniel Shiffman snake is a really good one to learn from, maybe pong and block breaker too :)
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+Kate McNamara got it thanks!
@piedesinistro8861
@piedesinistro8861 5 жыл бұрын
that's what i want to do when i graduate have fun programming
@boiimcfacto2364
@boiimcfacto2364 6 жыл бұрын
14:00 Glory Hallelujah! Praise the lawd!!!
@ianprado1488
@ianprado1488 6 жыл бұрын
I love how abrupt the ending is
@apexmike849
@apexmike849 8 жыл бұрын
I think you just reignited something in me ;-)
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
+ApexMike am glad to hear!
@mathematicalmatt
@mathematicalmatt 8 жыл бұрын
How did I not know about you before?! I don't know if this is where you accept challenge requests, but you should totally do langton's ant, and if possible multiple color langton's ant. Don't really know if that's the kind of thing Processing was designed for, but it would be awesome!
@TheCodingTrain
@TheCodingTrain 8 жыл бұрын
yes, i have have this one on my list!
@scebsy6524
@scebsy6524 2 жыл бұрын
Could you add backface culling to make it more efficient with more subdivisions?
@user-zo1kn8ob7h
@user-zo1kn8ob7h 3 ай бұрын
4:17 i want all the small things truth cares truth brings
@user-rp6qr3by5y
@user-rp6qr3by5y 6 жыл бұрын
can you tell me which video you made cover the .add() and the .get() function i am confused with them but i can not find them in your fundationary tuto
@sandipanroy7030
@sandipanroy7030 5 жыл бұрын
please carry on this typeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
Coding Challenge #3: The Snake Game
27:27
The Coding Train
Рет қаралды 3,3 МЛН
Coding the Collatz Conjecture
23:08
The Coding Train
Рет қаралды 130 М.
When You Get Ran Over By A Car...
00:15
Jojo Sim
Рет қаралды 28 МЛН
Coding Challenge #12: The Lorenz Attractor in Processing
21:21
The Coding Train
Рет қаралды 405 М.
Coding Challenge #89: Langton's Ant
20:58
The Coding Train
Рет қаралды 155 М.
Characters, Symbols and the Unicode Miracle - Computerphile
9:37
Computerphile
Рет қаралды 2 МЛН
The Fractal Menger Sponge and Pi
13:06
Stand-up Maths
Рет қаралды 453 М.
Coding Challenge #50.1: Animated Circle Packing - Part 1
28:32
The Coding Train
Рет қаралды 250 М.
Coding Challenge 168: MandelBulb 3D Fractal
28:02
The Coding Train
Рет қаралды 368 М.
Mathematical Impressions: The Surprising Menger Sponge Slice
6:13
Simons Foundation
Рет қаралды 109 М.
Exploring the Menger Sponge Fractal
9:34
Coder Space
Рет қаралды 9 М.
Dijkstra's Algorithm - Computerphile
10:43
Computerphile
Рет қаралды 1,3 МЛН
Coding Challenge 11: 3D Terrain Generation with Perlin Noise in Processing
22:44