Coding Challenge 180: Falling Sand

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2024

Комментарии • 441

  • @MagicalMongoose
    @MagicalMongoose 10 месяцев назад +488

    I appreciate you showing your mistakes and your process for fixing errors

  • @peek2much3
    @peek2much3 10 месяцев назад +71

    Literally NONE does it better in YT. The modern iteration of Bob Ross for coding and teaching. Absolutely engaging let alone entertaining.

  • @YourLocalGP8
    @YourLocalGP8 10 месяцев назад +601

    If we are now getting weekly/biweekly coding challenges, I will be so happy

  • @Kazner0h
    @Kazner0h 10 месяцев назад +362

    I know you mentioned that this was unplanned, but it was super nice to watch you have the same "Wait, why isn't that working???" moments that I do 😂

    • @TheCodingTrain
      @TheCodingTrain  10 месяцев назад +40

      I'm so happy to hear this feedback!

    • @lukeb0030
      @lukeb0030 9 месяцев назад +5

      i mainly get "wait, it is working??" moments

    • @divyankmalhan2154
      @divyankmalhan2154 9 месяцев назад +5

      @@lukeb0030 Ikr! or when you are stuck somewhere and your brain is like what if I do this without knowing the logic behind it.

  • @Muthwill
    @Muthwill 10 месяцев назад +9

    I've been programming for quite a few years now but never seemed to be able to have beautiful code. This was really helpful to watch, seeing your entire process of creating, refactoring and cleaning up and finally adding the comments

  • @vektracaslermd743
    @vektracaslermd743 10 месяцев назад +18

    As an aspiring pythonista, I don't know much about JS... but you are still an absolute gem to watch. Absolutely the Bob Ross of coding. Stay awesome!

    • @petervh1301
      @petervh1301 10 месяцев назад +1

      If you are experienced with Python the only confusing code should be the for loop syntax.

    • @f.a.383
      @f.a.383 10 месяцев назад

      "the Bob Ross of coding" couldn't have said it better myself

  • @daylen577
    @daylen577 10 месяцев назад +89

    You should have started your checking array from the bottom, that would have solved the sand separating like it does and instead just allow everything to drop as one big blob as it does IRL. Would probably not look as satisfying, but it would be a more accurate simulation as a real grain of sand does not wait for an already-falling grain of sand below it to be out of the way, it would instead add its own weight to the weight of the one below.

    • @Astervista
      @Astervista 10 месяцев назад +2

      Checking the array from the bottom would not change anything if the next frame is calculated only looking at the previous state. To solve that, you would have to account for a pile in air so that it all falls simultaneously. The striping is caused by grains in the air moving left and right because they have the cell below that’s occupied but not the cell below right or below left, while in the air that would not happen

    • @TheCodingTrain
      @TheCodingTrain  10 месяцев назад +19

      I've been thinking so much about this! I'm hoping to address these kinds of improvements on a future live stream.

    • @KylaraKuhn
      @KylaraKuhn 10 месяцев назад +6

      @@Astervista thing is.. you don't have to calculate from a previous state. Adjust the bottom in the present state and then there is a gap on the place it previously was so you can put the grain on top of that immediately down too. Then if you calculate an entire row that way, it is way easier to calculate left and right on the next row above it too. That way you only need to have a single row in a previous state (or otherwise the grain of sand will always favour filling up the first new free position where in reality the next grain of sand might just as well go there.

    • @Astervista
      @Astervista 10 месяцев назад +1

      @@KylaraKuhn yes, of course in this simulation it would not have made a difference, because the fall is in one direction. In principle though you could have wind or something else and cannot rely on the fact that modifying the array in place does not introduce weird feedbacks

    • @Ledenses
      @Ledenses 9 месяцев назад +1

      i think you can fix this while looking only at previous state still - check *all* tiles below and if any are 0, move the sand down.

  • @iogamesplayer
    @iogamesplayer 10 месяцев назад +41

    Very cool! I loved those flash games about placing stuff, and setting everything on fire with those "falling pixels".

  • @R74n
    @R74n 10 месяцев назад +51

    Thank you for bringing more attention to falling-sand games! We're developing a browser-based one focused on chemistry and science education!! 💙

    • @justin.campbell
      @justin.campbell 10 месяцев назад

      Hello! I remember visiting your site a couple years ago! Absolutely love it, beautifully simple design. I just checked out "Sandboxels", very fun to mess around with.

    • @NiceHyper01
      @NiceHyper01 9 месяцев назад

      I was going to check out your website, but then realized I already had. Sandboxels is really fun!

    • @sacul_6
      @sacul_6 7 месяцев назад

      You were what I thought of when I saw this video!

  • @pie9994
    @pie9994 10 месяцев назад +17

    Thanks for bringing back coding challenges. I find all the topics you cover very interesting.

  • @keppycs
    @keppycs 10 месяцев назад +13

    The animations are such a nice touch when trying to comprehend what you're explaining. You and the team are doing such an amazing job!

  • @a1000joys
    @a1000joys 10 месяцев назад +16

    Awesome. I'm so happy that Coding Challenge series still continues strong.
    I've been reading about sand simulators for the past few days and I thought this is an old video of yours that RUclips is suggesting. What a timing!

  • @AustroPower
    @AustroPower 10 месяцев назад +12

    Dan all your teaching and tuts are great, one can see you are a very passionate/dedicated man! 🙏👍💯

  • @mistakd3771
    @mistakd3771 10 месяцев назад +24

    my one small contribution:
    to make the sand look more grainy you can add a random number to the hue like this:
    grid[col][row] = hueValue + random(-13, 13);

  • @wlockuz4467
    @wlockuz4467 10 месяцев назад +3

    Just adding the colour made its so beautiful.

  • @whirlwind2831
    @whirlwind2831 10 месяцев назад +15

    Frequent coding challenges!! Couldn't have had any better start with 2024

  • @Absalon_melon
    @Absalon_melon 10 месяцев назад +3

    I love your content, whenever I felt coding as something tiresome and stressful looking at your videos made me fall in love with coding again, thanks!

  • @therockstar17
    @therockstar17 6 месяцев назад

    Your coding challenges are thoroughly enjoyable! I for one, with a mind that can barely stop working on a problem until it’s solved, watching you go through the process and laughing at yourself along the way is captivating. It’s nice to know this is exactly how I think through my own personal projects, not being anywhere near a professional at all. Starting from absolute scratch, deciding how to approach a problem by breaking it up into parts and then adding little bits at a time until it’s a complete program is satisfying and delightful

  • @jabrikolo
    @jabrikolo 10 месяцев назад +3

    I loved this! I tried doing this a few years ago and I just love how you explained it. It's also very cool to add more elements like water and stone

  • @alexsandergutierrezgoncalves
    @alexsandergutierrezgoncalves 10 месяцев назад +7

    very cool, p5 js many possibilities, one thing I always do when I draw the value of a 1D matrix on the canvas that is 2D is to convert the 1D index of the matrix to 2D coordinates like this:
    let x = i % cols;
    let y = floor(i / cols) % rows;
    so I can use a 1D array and just a single for loop.

  • @LuisCurrupaki
    @LuisCurrupaki 7 месяцев назад

    Maaaan, this video was greatly inspirational! Your exictement about your coding is heartwarming!
    It really shows you're having fun, and kept me peeled to the reasoning with you.
    Marvelous job! Thanks for bringing us joy!

  • @GiovanniCamellini
    @GiovanniCamellini Месяц назад +2

    This is the simplified version of what happens in the mobile videogame industry nowadays but without super expensive frameworks driven by even more expensive managers.

  • @shanehebert396
    @shanehebert396 10 месяцев назад +13

    Some years ago, I wrote something similar, but more connected with our current time of year (here in the USA) -- a snowfall simulation. Instead of having a single drop point, a (parameter controlled) number of 'snowflakes' were spawned at random points on the topmost line of pixels and then 'drifted' down (didn't go straight down, they had a chance to perturb the path to the left or right each time). Each had a random velocity (also parameterized for max). I also put a parameter for wind so all the snowflakes would tend to drift with the wind. All the parameters were sliders so they could be changed while it was running. Snow would accumulate at the bottom and would fall down to the localize minimum point to the left or right. It was kind of fun to write and watch.

    • @petervh1301
      @petervh1301 10 месяцев назад

      Thats a nice challenge! Ill be building that tomorrow!

  • @OddlingCore
    @OddlingCore 10 месяцев назад +4

    Was trying to find motivation to do my coding homework today and got the RUclips notification for this video got incredibly excited checked to make sure that this is the same coding language that I’m learning in my class, and I gasped and yelled “Yesssssssssss”, aloud in glee!

  • @alexandermcclure6185
    @alexandermcclure6185 10 месяцев назад +1

    I just encountered this series (this is my first episode that I watched) and I am already LOVING IT! I have been wanting to do a "falling sand" kind of project at some point (and give it custom rules!) so that everything would be so much easier! You just earned a subscriber :)

  • @iJackJP
    @iJackJP 2 месяца назад +2

    Dude there is a optical ilusion when you create the grid: 4:23, if you stop it and watch the grid. It seems to have diagonal black lines crossing the white squares vertices. The more you wathc the grid it get easier to watch whose diagonal lines.

  • @mattshu
    @mattshu 10 месяцев назад +2

    you are the very reason javascript code is even slightly legible to my eyes. thank you so much!

  • @endunry
    @endunry 5 месяцев назад +1

    I stopped watching yt and thus also stopped watching your vids in the past years. But i just saw that you still create These amazing vids. You probably wont see this.
    But your videos where the first contact i had to computer science and it got me hooked on. Since the starfield challenge i Watched and Code every Challenge you posted and learned to Code. Because of this Joy now have a finished cs degree and a job as a software Developer. And i think withou your Videos and without the joy and passion you put into educating others i wont be where i am today... Im really grateful of what you do and i hope that you inspire a lot of people like me in the future. Thank you sir

    • @TheCodingTrain
      @TheCodingTrain  5 месяцев назад

      This makes me so happy to hear thank you for sharing!

  • @sirflimflam
    @sirflimflam 10 месяцев назад +1

    Man I wish youtube was a thing when I was a kid. Channels like this would have made self learning a lot easier than it was.

  • @orbyfied
    @orbyfied 10 месяцев назад +3

    holy shit ive been waiting for this without even knowing it
    pls continue on this project

  • @Soundole
    @Soundole 10 месяцев назад +2

    This was great to follow along - I love how you show your thought process when it comes to debugging!

  • @TrosindelPascua-up6tm
    @TrosindelPascua-up6tm 10 месяцев назад

    Your the reason i started programming, i like your personality and just listening to you makes me calm down. I hope you have a good life. ❤❤❤

  • @nospecificity7690
    @nospecificity7690 10 месяцев назад

    Great job I think the way you talk through debugging and show the troubleshooting process is incredible and will help lots of people learn!

  • @jermz79
    @jermz79 3 месяца назад +3

    The two projects I used to always do when learning graphics programming in different languages (Rapid Euphoria was fun, wonder if that's still around) were John Conway's life and a falling sand/snow/particle simulator with a graphic mask, like a cabin or something, for the sand to roll off of.

  • @AdamRidley11
    @AdamRidley11 10 месяцев назад +2

    To eliminate the striping you could loop from the bottom up, you need the lowest piece of sand to move out of the way so that sand above it can fall in the same update call.

    • @flameofthephoenix8395
      @flameofthephoenix8395 8 месяцев назад

      Yes! And this would also eliminate the need for a next frame grid as the blocks would always be visited only once even if they fall.

  • @mudkip9894
    @mudkip9894 6 месяцев назад

    This guy is a great teacher. I got my current programming mindset from watching these videos and that has landed me working on my largest project so far, Open world Minesweeper in Minecraft. I might even try my hand at making a video on it, which is unfortunately late in because I already have a basis on it and am adding more feature to flesh it out some.
    Quick tip for those curious about Processing. It is a library and compiler that allows you to learn programming without major setup. I never touched the JavaScript, but the Java side is just as brilliant. What does this have to do with Minecraft? Both use Java as a base. I might explain more sometime, but you might as well try processing since it is free.

  • @pete_thompson
    @pete_thompson 10 месяцев назад

    One smal timesaver - instead of a loop to fill the array with zeros, you can set it when you create it - arr[i] = new Array(rows).fill(0). The fill(0) will put a zero in every element. Great videos!!

  • @minijimi
    @minijimi 10 месяцев назад +8

    Fantastic job Dan!

  • @gauravrawat7175
    @gauravrawat7175 10 месяцев назад +1

    Never stop these coding challenges

  • @RicoGalassi
    @RicoGalassi 10 месяцев назад +6

    This used to be my absolute favorite game...thanks Dan!!!!

  • @anon_y_mousse
    @anon_y_mousse 10 месяцев назад +1

    You should make this into a game. You're a gardener with a water bucket trying to get every plant. The water absorbs in over time and you have to make sure nothing goes dry. Some plants could act like sponges and soak up a lot, while others would barely sip. To fit the color scheme, the plants could grow Skittles and you could be required to color coordinate the water you use on each plant to correctly handle each "flavor".

  • @imjojo9265
    @imjojo9265 9 месяцев назад

    Love that it wasn’t planned, got to see the actual thought process on how to work things out

  • @amirThePiper
    @amirThePiper 2 месяца назад +1

    Man, I was looking for a movie or a blooper to watch. But damn, this is interesting and fun ❤🙏

  • @jasondunken
    @jasondunken 10 месяцев назад

    another great video dan! thanks as always! when you are randomly choosing to move a pixel left or right, you are allowing pixels to merge with each other. if two pixels are next to each other, one has a pixel under it and the other doesn't, both pixels could end up in the same position after the update. this happens not only when the pixels hit the bottom, but also when you are spawning them with the mouse, that's why the spawned pixels are striped. the rules should check if it can fall right or left or one at random, but only if the pixels underneath aren't also falling.

  • @Zac8668
    @Zac8668 10 месяцев назад +4

    Amazing video! Seeing you code is really entertaining

  • @stighenningjohansen
    @stighenningjohansen 8 месяцев назад

    The most mindblowing demo I have ever seen was written in Euphoria, from 1993. Was an .exe someone
    contributed, and showed an eternal trip floating forwards way up in the clouds. It was simple, but very complicated and
    I cannot forget it.

  • @unoriginalpun
    @unoriginalpun 10 месяцев назад

    Line 111 When you use the random to decide if the sand will fall left or right you negate that by making the belowB subtract dir. (line 117)
    It would be cool to add in a topple function similar to the sand piles program you made a long time ago. So that once a pile reaches a certain instability it topples left and right.

  • @BotaTamas85
    @BotaTamas85 10 месяцев назад +50

    I loved the 'popcorn guy', especially when it dropped you a popcorn. 😂 I like when someone can practise self-criticism in a funny way 😊

  • @andreykanishchev1724
    @andreykanishchev1724 7 месяцев назад

    Great work, thanks! Noticed that the amount of falling sand is greater than the amount of sand on the ground. This is due to the fact that there may be two granules in one place. It worth to add analysis of the grains on the left and right on same level, so that a grain of sand that has a void underneath will fall first compared to a grain of sand that should hit the same pixel on the left or right.

  • @replays4026
    @replays4026 10 месяцев назад

    Wow, impressive! I remember, when I used to do a random things on thoughts, but I don't do It now. Your video inspires me to back to these great days and make beautiful things on canvas

  • @beterbarker
    @beterbarker 7 месяцев назад

    Loved the video! I've mostly done business programming, so I've never had to do anything like this. I'm definitely more interested in writing simulations in code. Comments in the code definitely made me wince.

  • @Lealwbs
    @Lealwbs 10 дней назад

    I recently discovered this channel and I think it's amazing!

  • @abdessadekelaasri8862
    @abdessadekelaasri8862 10 месяцев назад

    It's actually great that this video was unplanned, It is better to watch you go throught the proccesing of fixing the errors. thank you! do more of there :)

  • @kudorgyozo
    @kudorgyozo 10 месяцев назад

    You make programming fun again with every coding challenge!

  • @mihneagogu1389
    @mihneagogu1389 9 месяцев назад

    damn I remember watching coing train videos as a 15yo kid and thinking that was so cool. Time passes and now I'm 22, have a master in cs and am working fulltime in this field. Time really flies. Never thought looking a these random videos so many years ago would lead to this one way or the other. Great to see Daniel is as great as ever!

  • @jareddominiccaraan1988
    @jareddominiccaraan1988 3 месяца назад

    You're like the Bob Ross of programming 💕. Makes me want to solve coding exercises again.

  • @Baekstrom
    @Baekstrom 9 месяцев назад +1

    You also left another exercise for the viewers: Remove the stripey pattern. It's easy to realize that it happens because the sand grains are processed one after the other, and if one grain has another grain under it, it won't be moved this pass, even though the grain under it should itself me moved and leave room for the one above it. It is also easy to come up with the idea that maybe if you process the grid from the bottom and up, then you could maybe "fix" that issue. However, that solution is not very satisfying, because it depends on the knowledge that sand always falls down. What if you had a mix of particles with different properties, like sand and hot "air" that rises?

  • @jaitjacob
    @jaitjacob 10 месяцев назад

    Adding hue and seeing those rainbow layers was so much fun, I gonna make a version of mine taking inspiration from you. Thank you

  • @sebastineodeh8612
    @sebastineodeh8612 10 месяцев назад

    Thank you so much for this coding challenge. I decided to implement it with flutter, taught me quite a lot as regards drawing pixels on the screen

    • @TheCodingTrain
      @TheCodingTrain  10 месяцев назад

      Feel free to share in the passenger showcase! thecodingtrain.com/showcase

  • @maartenofbelgium
    @maartenofbelgium 10 месяцев назад

    FYI, the line pattern appears because the grid is checked columnwise from top to bottom.
    Changing it to row-wise bottom-to-top makes them disappear.
    You also get a fun delayed sand shape effect due the left-right randomness.
    Nice video!

  • @CocoaBeans660
    @CocoaBeans660 10 месяцев назад

    These make me so incredibly happy I don't know why

  • @Galmok18
    @Galmok18 9 месяцев назад

    As a final touch, you should really update the pixels from they bottom up. Doing it like you did makes a piece of sand right above another that is free falling pause until the piece below has been dropped down away.

  • @jorgen7974
    @jorgen7974 10 месяцев назад +178

    Bro mentioned everything except the powder toy

    • @TyPh11
      @TyPh11 2 месяца назад +1

      That one is just a masterpiece!! Cannot recommend enough!

  • @realElzie
    @realElzie 10 месяцев назад

    You present coding in a very friendly way, thank you

  • @CodeNascher_
    @CodeNascher_ 10 месяцев назад +4

    re: Sandspiel (german for sand game)
    just fyi - Sand rhymes with hunt
    but props for getting the "spiel" part correct
    greetings from 🇩🇪

  • @ohmynoun
    @ohmynoun 7 месяцев назад

    In JavaScript, you can use "switch (true)" instead of a big chain of else-ifs. This can help with readability when alternative refactors aren't viable for one reason or another.

  • @Mali.97
    @Mali.97 9 месяцев назад

    Just found your channel i normally dont comment but you are an absolute hero

  • @kieran.stafford
    @kieran.stafford 10 месяцев назад +1

    Dan, it's always a treat to see a new video from the Shiffmeister and Mrs Pickle. Loving the new production values although I'm glad you keep the screw ups and comedy. Makes it so entertaining and human in a domain that can be very ego driven. Just occurred to me - a great name for a cop show on TV that - The Shiffmeister and Mrs Pickle :)

  • @MarcGauch
    @MarcGauch 10 месяцев назад

    haven't watched any of your video in years. i love the new editing style😊

  • @theclockworkcadaver7025
    @theclockworkcadaver7025 6 месяцев назад +2

    14:00 why not use optional chaining, like grid[i+dir]?.[j+1] - then it doesn't matter if grid[i+dir] is undefined

  • @guillermocasalcaro270
    @guillermocasalcaro270 9 месяцев назад

    You had those horizontal patterns in the falling sand because when vertically aligned grains of sand fall, the top one checks to see if there is another grain below it, if there is it will move diagonally to one side of the bottom grain. That's why you can't have vertically aligned grains of sand falling at the same time. I think this is easily fixed by looping through the state from the bottom up and using the new board state (instead of the previous) to check the positions below the actual one.

  • @sonik382
    @sonik382 10 месяцев назад +4

    Love those coding challenges...thank you Dan!!!

  • @mews75
    @mews75 10 месяцев назад +2

    I fucking love your channel, you basically got me back into coding back in 2020 and now I'm going to college for computer science

    • @zandrew8648
      @zandrew8648 9 месяцев назад

      great for you! i had decided to major in comp sci before i started watching Coding Train, but these videos do open up my eyes to some of the fun problem solving bits I hadn't thought about for some scenarios. very fun!

  • @eocron
    @eocron 10 месяцев назад

    You have fixed size window, that means your task of "moving" set of pixels can be just....offset modulus height. So you have a column and said offset, when you perform life iteration, you increase offset, nothing more, O(width) operation. When you draw - you draw canvas with this offset. When physics comes at play - you make offset a zero, perform interactions. This idea is expandable to 1D/2D/3D objects as well. For 1D it could be just run length encoded bits, for more complex spaces octree will do the job.

  • @TodePond
    @TodePond 10 месяцев назад +3

    nice sand i should try that

  • @thomaswhyte5107
    @thomaswhyte5107 7 месяцев назад

    As a newbie when it comes to coding and having no idea how I would even attenpt this,I enjoyed wayching it.

  • @FilthyAnimal893
    @FilthyAnimal893 10 месяцев назад

    Fun facts:
    There have been several clones of this type of game through the years, including FallingSandGame, SandSandSand, and wxSand, but the first one known is from a Japanese creator in 2005 which goes by the name World of Sand.
    Some of my first ever interactions with writing code (or at least pseudo-code) was with wxSand, where you could make your own elements and interactions by editing a mod file which came with the game, in which you establish elements and their base properties, and then define interactions between elements.

    • @johncotterell1649
      @johncotterell1649 6 месяцев назад

      The first attempt at something like this (that I know of) was the game Cataclysm on the Acorn Archimedes in 1992

  • @metalheadmaniac8686
    @metalheadmaniac8686 5 месяцев назад +2

    You can make it even more efficient by not having the computer go through the entire 2D array to find sand; instead, you can have an array that has the x positions of every piece of sand and another array that has the y positions of every piece of sand and use the numbers stored in those arrays to find a piece of sand that is in the grid. What if the grid was 1 million by 1 million and you had the computer go through the entire 2D array to find one piece of sand? I would not be surprised if the computer started the robot uprising just to get you.

  • @angeloliver2825
    @angeloliver2825 10 месяцев назад

    We need to apply a check between previews a new position if we want to apply a gravety force.
    For example, if we have a great gravety value such that 5 increse spaces, all of this space are need a stop down check...

  • @fg786
    @fg786 10 месяцев назад

    Here's another idea. Give a bias for the left and right movement to traverse fruther than 1 cell, so that it can move 2 or 3 cells to the left or right. This would give you shallower angles on one side and make the dune look windswept. And with every start of a drag movement of the mouse a new bias is calculated.

  • @SamuelAndradeGTutos
    @SamuelAndradeGTutos 10 месяцев назад

    It has those stripes cuz you are looking from 0,0 to col,row. You should go backwards cuz they are falling down. It happens cuz you are checking the bottom pixel and, before the bottom pixel moves, it is there yet.

  • @w4ffle3z
    @w4ffle3z 9 месяцев назад +1

    I like to use r and c rather than i and j when working with 2d arrays that specifically refer to rows and columns, just so I don't mix up whether i or j is meant to be a row or a column

  • @geoffwagner4935
    @geoffwagner4935 10 месяцев назад

    Wow this one is very pretty,... fun relaxing and easy going on this one. Really like the colors and artwork in this one. nice seeing new stuff

  • @requestfx5585
    @requestfx5585 9 месяцев назад +1

    People before functions were used to keep the code organized and easy to read

  • @LetiziaMondo
    @LetiziaMondo 10 месяцев назад

    Your mood makes me happy

  • @GlassImpressions
    @GlassImpressions 9 месяцев назад

    I doubt I will ever code but your video inspired me and I subbed. Thank you!

  • @bartdemeyere
    @bartdemeyere 9 месяцев назад

    Nice video. it inspired me to create a samegame game. Your remove groups of blocks of the same color, blocks are falling down and empty columns are trimmed away. No p5.js but vanilla js and the html5 canvas element. And an implementation of the floodfill algorithm te find cluster of blocks of the same color. Fun project to do and a few tricky parts to deal with. :)

  • @JackAllpikeMusic
    @JackAllpikeMusic 10 месяцев назад

    I'd love to see this expanded with the more complex behaviour of sand shooting out to the sides further based on it's velocity, creating less perfect-pyramid like shapes.

  • @DinoDragon6
    @DinoDragon6 10 месяцев назад +1

    This is the true coding experience

  • @erroneum
    @erroneum 10 месяцев назад

    The immediate solution to adding physics to the simulation is to change the value type for each cell from just the hue to a tuple of associated values, such as hue, velocity vector, maybe mass, maybe material type (then you can add rules for different types of materials, such as water and sand, where sand will sink through water), etc. From that, on each update, for each cell with non-void contents, you check that it can travel by the amount indicated in it's velocity vector, then if if it can, put it there, and update the vector based on things like collisions, the pull of gravity, etc.

  • @zeyusdotcom
    @zeyusdotcom 5 месяцев назад

    I've been coding since forever, I'm not even sure why I started watching this, but I'm so happy I did! What a great video, you're an engaging and entertaining teacher, and I think (it's hard to say) you present it in a way that's accessible for people of all levels. Awesome work. 💗

  • @Afshin-Salehi
    @Afshin-Salehi 7 месяцев назад

    You are a god.
    Thank you for what you are.

  • @ApexGameStudios
    @ApexGameStudios 10 месяцев назад

    thanks for u piece of code that has given me an idea of writing up the gravity implementation in ur code

  • @flameofthephoenix8395
    @flameofthephoenix8395 8 месяцев назад

    5:30 Just before anything happens I'd like to point out that if you iterate on the grid as you traced your finger you'd get weird movement as each block of sand would look for the next to be air then when it sees that it is in fact not air it stays still but the last block will see air and so will move resulting in them separating, additionally, the last sand block due to its movement will fall all the way to the bottom in just one frame.

    • @flameofthephoenix8395
      @flameofthephoenix8395 8 месяцев назад

      5:48 Ah, well you already fixed part of that problem; however, you'd still get them separating out as a result of only the last block moving.

    • @flameofthephoenix8395
      @flameofthephoenix8395 8 месяцев назад

      15:20 Ah! I bet you're getting close to the problem as I described it.
      Indeed! Now, I wait in bated breath for you to fix this. Chop, chop!

  • @flameofthephoenix8395
    @flameofthephoenix8395 8 месяцев назад

    15:02 You could probably keep the grid lines by just drawing larger lines from side to side. This would be more efficient than before while still having the grid lines.

  • @feelinghealing3890
    @feelinghealing3890 10 месяцев назад

    I would make the sand speed up by doing another 2-4 checks for free spaces further below and setting a state on sand grains that determines its current speed from the last drop. So every step that it falls 1 pixel, it checks if it can fall 2, every step it falls 2 pixels, it checks if it can fall 3 or 4 and so on.
    I would also try making sure that at rest grains do not do this all the time, so at rest pixels get none of these flags and instead just check if they can fall or not.

  • @Bolli1983
    @Bolli1983 10 месяцев назад +1

    the Bob Ross of coding, thank you!

  • @BristlyBright
    @BristlyBright 10 месяцев назад

    Nice challenge!
    Reminds me of one of the challenges in advent of code 2022.
    I miss the times where the writing of the code was not fast forwarded. That time is crucial to reflect over the code. It is much more overwhelming when you constantly are getting information, and not time to process the information.

  • @vladthe_cat
    @vladthe_cat 9 месяцев назад

    The Powder Toy is another excellent falling sand simulator, it is quite in-depth and has many materials and elements

  • @jayjasespud
    @jayjasespud 10 месяцев назад

    I just watched a video the other day about Falling Sand via Cellular Automata.. What a coincidence. It was by a RUclipsr named MARF.
    Glad to see the Coding Challenges make a return!