Coding Challenge 124: Flocking Simulation

SdĂ­let
VloĆŸit
  • čas pƙidĂĄn 23. 07. 2024
  • In this coding challenge, I create a flocking simulation in JavaScript based on Craig Reynolds "boids" algorithm. Code: thecodingtrain.com/challenges...
    đŸ•č p5.js Web Editor Sketch: editor.p5js.org/codingtrain/s...
    đŸŽ„ Previous video: ‱ Coding Challenge #123:...
    đŸŽ„ Next video: ‱ Coding Challenge 125: ...
    đŸŽ„ All videos: ‱ Coding Challenges
    References:
    📄 Craig Reynolds' Paper on Boids: www.red3d.com/cwr/boids/
    📕 Autonomous Agents - Nature of Code: natureofcode.com/book/chapter...
    📘 The Computational Beauty of Nature: mitpress.mit.edu/books/comput...
    Videos:
    🌐 Original Boids Simulation: ‱ Craig Reynolds - Origi...
    âžĄïž Vectors - The Nature of Code: ‱ 1.1 What is a Vector? ...
    đŸȘ‚ Autonomous Steering Agents: ‱ 5.1 Autonomous Steerin...
    🔮 Coding Train Live 162: ‱ Coding Train Live 162:...
    Related Coding Challenges:
    🚂 #69 Evolutionary Steering Behaviors: ‱ Coding Challenge #69: ...
    Timestamps:
    0:00 Introduction to flocking!
    2:07 What are boids?
    2:33 Creating a system of boids
    7:06 Discussing the flocking algorithm
    7:38 Alignment!
    21:48 Cohesion!
    28:37 Separation!
    37:00 Things to try!
    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: thecodingtrain.com/discord
    💖 Membership: czcams.com/users/thecodingtrainjoin
    🛒 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...
    #flocking #creativecoding #autonomousagents #processing #p5js

Komentáƙe • 254

  • @MasterHigure
    @MasterHigure Pƙed 5 lety +180

    32:00 This makes diff have length 1, not be inversely proportional to d. You have to divide by d^2. I do think the "vortex" formations you get (where boids fly through the center of the local flock, out to the side, back around, and through the center again) kinda cool, though. Also, I don't think the boids' perception range goes past the edge-wrap of the screen (that looks like a hassle to code, though).

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety +50

      Omg yes indeed, oops! Thank you for this correction. Pinning the comment!

    • @VladSandu79
      @VladSandu79 Pƙed 5 lety +13

      "perception range goes past the edge-wrap of the screen": we can see this "bug" at 20:23 on the right of the viewport how the boids keep apearing or dissapearing, also lining up vertically on the edge.

    • @PhilBoswell
      @PhilBoswell Pƙed 5 lety +9

      How about if every time you had
      let d = dist(this.position.x, this.position.y, other.position.x, other.position.y);
      you substituted
      let d = dist((this.position.x + width) % width, (this.position.y + height) % height, (other.position.x + width) % width, (other.position.y + height) % height);
      That seems to work for me
I suspect it would help if we abstracted out the selection code
is that the reFactor Song I hear playing? ;-)
      Here's my current version of this sketch, I added a couple of extra little touches ;-) editor.p5js.org/NotACat/full/SkoYSoCyV

    • @MasterHigure
      @MasterHigure Pƙed 5 lety +4

      ​@@PhilBoswell I don't see how that fixes the wrapping. In fact, it wouldn't change a thing at all, as
      (this.position.x + width) % width == this.position.x
      and same with other, and same with y and height (except possibly for a boid lying EXACTLY on the edge, I don't know enough about JS to tell). If they are on opposite sides of the screen, you'd have to SUBTRACT width or height from the one furthest to the right or furthest down (and you'd have to figure out whether it's this or other, and whether it's just x, just y, both x and y, or x for one and y for the other). That looks like a hassle to me, with mins and maxes all around, and lots of ifs flying around. Definitely put it in its own function.

    • @PhilBoswell
      @PhilBoswell Pƙed 5 lety +1

      @@MasterHigure I had a fit of sense and looked on StackOverflow ;-)
      How about
      let d = sqrt(pow(min(abs(this.position.x - other.position.x), width - abs(this.position.x - other.position.x)), 2) + pow(min(abs(this.position.y - other.position.y), height - abs(this.position.y - other.position.y)), 2))
      That seems to work rather better than my feeble effort and it's not too expensive either ;-)

  • @potatoes8169
    @potatoes8169 Pƙed 5 lety +191

    last video i watched, he didnt eat lunch, this video he still hasn't eaten lunch. this makes me feel he was hungry for weeks man. lol

  • @KristianPedersen
    @KristianPedersen Pƙed 5 lety +62

    3:44 To disable autocomplete in VS Code, turn off "Accept suggestion on commit character".

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety +47

      This from the the creator of the THIS DOT song everyone!!!! â€đŸ™â€đŸ™â€đŸ™â€đŸ™â€đŸ™â€đŸ™â€

  • @abdimalikosman559
    @abdimalikosman559 Pƙed 5 lety +26

    Not all heroes wear capes. Hats off dude, you are just amazing.

  • @zaynbaig3157
    @zaynbaig3157 Pƙed 4 lety +8

    I have probably seen this ten times, and I find it so intriguing every time. Thanks, Dan!

  • @ezequiel9055
    @ezequiel9055 Pƙed 2 lety +7

    This channel is GOLD! Dan is SO GOOD at explaining everything specially the most complex things.

  • @Ron-op8es
    @Ron-op8es Pƙed rokem +4

    This is such a good video, I attempted this a year ago but wasn't able to figure out all the logic on my own. I just didn't understand how 2 numbers could represent a dot moving in any direction. We only need to change the x and y values, but how you would maintain the overall speed was a mystery.
    Finally, after 2 full watch throughs and a full year later I was finally able to code this just using vanilla js and html canvas. I created Vector class for the math bits, and now it actually makes sense why we would need to divide the velocity vector by its own magnitude, because it gives you a unit vector with magnitude 1 but with the same direction as before so you can scale it by whatever factor you want!!!

  • @UweEichel
    @UweEichel Pƙed 5 lety +2

    This was an amazing video! Thanks Dave. I enjoy having these kind of videos which are a bit longer than usual.

  • @lopa8519
    @lopa8519 Pƙed 5 lety +4

    The editing in this video was great. Loved this one, really interesting ! You're amazing for doing all of this for free. :D

  • @Dgiulian
    @Dgiulian Pƙed 5 lety +1

    I subscribed to the channel a long time ago because of the nature of code series. This is was a really nice reminder of that topic

  • @sayanghosh6996
    @sayanghosh6996 Pƙed 5 lety +121

    19:53 Dan.exe has stopped working

    • @kushagra64
      @kushagra64 Pƙed 3 lety +2

      100 th like :D
      Edit: wow someone like it :)

  • @gid9551
    @gid9551 Pƙed 5 lety +3

    Hey Dan! Greetz from Denmark. Just here to say thanks. Been following your coding challenges for a while now and amazed at the great content and enticing questions you pose to your viewers (like in this video - SO many things I could think of, if only I had the time). In the phrase 'standing on the shoulders of giants' I very much consider you a (teaching) giant. Keep on choo-ing!

  • @BulletProofCupid7
    @BulletProofCupid7 Pƙed 2 lety +26

    You should advertise your book more often. It took me way too many videos of yours to discover that you've written a book! A book with all you're teaching in videos! I would've gotten it way sooner, it's a really nice read so far :)!

  • @andrasfauszt1693
    @andrasfauszt1693 Pƙed 5 lety +42

    Different mass would be fun. Few agile small boid run circles around a the heavy ones. And its also easy to implement and visualize with different radiuses/sizes.

  • @MrPeloseco
    @MrPeloseco Pƙed 5 lety +3

    Dan is here to introduce us and guide us through p5 and or processing. But I have to thank processing for introduce me to Dan and his videos/books. A total blast!!

  • @echoes6092
    @echoes6092 Pƙed 5 lety +8

    Thank you so much for doing subtitles :) it really helps

  • @Eman6240
    @Eman6240 Pƙed 4 lety

    Love your videos. Love the way you work towards the solution.

  • @toastrecon
    @toastrecon Pƙed 5 lety +9

    So cool! Some other ideas: give the birds "momentum" and have them controlled by some kind of PID controller algorithm to make them seem more natural. You could also adjust the perception radius to be anisotropic and stochastic, so simulate a bird's vision. So, they could only "see" birds right in front of them, and sometimes they wouldn't see ones to their sides and never behind them.

    • @yannmassard3970
      @yannmassard3970 Pƙed rokem +1

      bird vision that flock (like pigeons) is almost 300d horizontally and 150 v

  • @tylerhorton9807
    @tylerhorton9807 Pƙed 4 lety +1

    I've always wrote letters to my teachers.. always, so I can appreciate their brilliant mind helping me discover new ways to channel my genius, even if it's not so genius at times. I would just like to say, I've became an intermediate developer on many other platforms other than java due to your tutorials. I have even made realistic gears mechanics to attempt at making computer engineering into a sandbox style, so far it's going good.. and this is one of many features I am implementing into it, but beings as I have no developer team, and I'm still getting online to find tutorials for certain algoritms I've no knowledge of yet, because I'm self-taught moreorless, it'll most likely be 2025 before beta is even a thing..

  • @RedHair651
    @RedHair651 Pƙed rokem

    This is flocking awesome. Cracking a cold one with the boids.

  • @tomd8168
    @tomd8168 Pƙed 5 lety

    That was really awesome, thanks!

  • @Chayat0freak
    @Chayat0freak Pƙed 5 lety +2

    an easier dispersal algorithm is simply to get the CoM calculated for cohesion and move away from that point if the Boid is already too close. Make sure this force is strong enough to counter the force of attraction. but is inversely proportional to the distance. Also you can speed this up by using distance calculations that avoid square root calculations

  • @TheFinagle
    @TheFinagle Pƙed 3 lety +3

    20:20 when your adjusting the direction your allowing the oppsing vectors to cancel out. across 100 random vectors the average is close to 0. you want to change the direction to match without adjusting the length of individual vectors (unless that boid intends to speed up or slow down toward a goal).

  • @BorisJensen
    @BorisJensen Pƙed 9 měsĂ­ci +1

    20:25 The reason everything slows down is that the average velocity of all boids is close to zero. All the random starting velocities even out, and the average velocity of neighbours for a given boid will also be close to zero, and then we try to modify that boid's velocity towards that average

  • @atrumluminarium
    @atrumluminarium Pƙed 5 lety +13

    An addition to the "optimisation" discussion, rather than the inverse distance, use the inverse square. Then write an alternative distance function with just d=∆xÂČ+∆yÂČ to get rid of messy square roots

  • @sindreeidskrem2137
    @sindreeidskrem2137 Pƙed 5 lety +18

    đŸŽ” My vector brings all the local boids to my local position!đŸŽ¶

  • @SMujiH
    @SMujiH Pƙed 5 lety +50

    "We're just going to start with a blank, pre-stretched canvas with a thin coat of liquid black pixels"

  • @LucaPrn
    @LucaPrn Pƙed 5 lety +2

    I couldnt be more lucky..a video from the god of processing exactly when I was planning to do a project on flocking :) thanks....god....of processing :)

  • @pyrookil480
    @pyrookil480 Pƙed 5 lety +61

    4:53 "There it is, there's by BOIIII"

  • @zanejohns777
    @zanejohns777 Pƙed 5 lety +3

    Your teachings are very inspiring, sir. I have learned so much, and I am very thankful for what you contribute. I was thinking about the section in which there is a division by distance. As the distance approaches zero, the result will become very large, potentially causing a less smooth behavior, though maybe only for a couple of frames or so. It may be good to consider a minimum distance before any division occurs. That is my two cents, anyhow.

  • @XiSparks
    @XiSparks Pƙed 5 lety +2

    This is flocking awesome.

  • @kodefattern
    @kodefattern Pƙed 5 lety +5

    I am still in shock and awe that you feature my little "Refactor" song :) I still love your videos, and get inspired by them :)

    • @kodefattern
      @kodefattern Pƙed 5 lety +2

      Actually, not trying to hijack your video or anything like that, but I've have gotten a lot of emails from people wanting me to create a full length song of the "Refactor" song. I may do that, but just to put the record straight, it was only meant as a jingleish thing for you to use in a video if you wanted to. I hope you don't mind if I extend it and make it into a real song.

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety +5

      Yes, and then we should collaborate on a music video!!! đŸŽ”â€

    • @kodefattern
      @kodefattern Pƙed 5 lety +2

      @@TheCodingTrain deal!

    • @GodofChookie
      @GodofChookie Pƙed 5 lety +1

      @@TheCodingTrain you know you have to do it know, don't you

  • @TiffanyNg100
    @TiffanyNg100 Pƙed 2 lety

    your energy never disaapoiint me

  • @emanouda9797
    @emanouda9797 Pƙed 3 lety

    That was the best explanation I've ever heard or seen! are you planning to code challenge the pedestrian behavior soon!

  • @pythonexploits8364
    @pythonexploits8364 Pƙed 5 lety +2

    I would love to see an actual game development series of him, just watching him develop a larger game.

  • @twinpotatoes5513
    @twinpotatoes5513 Pƙed 5 lety +1

    This is so cool! Anything to do with AI is fascinating because you can control them yet you let them be free. Do more AI related videos please :D

  • @monocore
    @monocore Pƙed 10 měsĂ­ci

    Ive learnt VEX with your tutorials. Youre amazing.

  • @TonyZhang01
    @TonyZhang01 Pƙed 5 lety +1

    adding this
    strokeWeight(2);
    line(this.position.x, this.position.y,this.position.x+this.velocity.x*3,this.position.y+this.velocity.y*3);
    to the bottom of the show function let you see the direction.
    also, when the flock teleports when it touch the edge, the forces are not teleported which means the flocks can split in two when half teleports and half doesn't

  • @6Pope9
    @6Pope9 Pƙed 6 měsĂ­ci

    20:40 It slows them down because of the same reason why they make a parfect circle at the start (6:06). They each have a different direction so when they're aligning they take a average velocity so it cancels out.

  • @badunius_code
    @badunius_code Pƙed 2 lety +2

    37:20 just run flock() and update() in two consecutive cycles; no need to snapshot.

  • @en3sis
    @en3sis Pƙed 5 lety +16

    Hey Dan, if you need to rename a variable just select it once then press command + f2 or command + D and rename it =)

  • @kevnar
    @kevnar Pƙed 5 lety +12

    When you're at 30 minutes in, and he says Separation is difficult, but the video ends in 12 more minutes... it's not that difficult, for Dan.

  • @ghghvfugx_gh35
    @ghghvfugx_gh35 Pƙed rokem

    this man is fantastic

  • @user-xr9lx9ui7l
    @user-xr9lx9ui7l Pƙed 2 měsĂ­ci

    you are a gem

  • @lizabeti3457
    @lizabeti3457 Pƙed 5 lety +5

    Awee making that without lunch You’re crazy 😂

  • @alexlindsay9002
    @alexlindsay9002 Pƙed 5 lety +3

    Something else one could do is add a little bit of randomness.... Boids aren't perfect in how they follow the rules ... so maybe they vary within a range of the ideal adjustment. Also could add some background noise...maybe perlin noise which creates a 'wind' force which acts on boids based on their position...

  • @michaelwalker1013
    @michaelwalker1013 Pƙed 5 lety +14

    Hey Dan,
    Just wanted to sincerely thank you!
    I'm still in my first year of teaching myself coding and your style of videos,
    "I'm gonna show you my way and explain how it works YOU (the audience) refactor it".
    Has helped me tremendously!
    I made my own Javascript "WAR" card game from scratch, No tutorials!
    Quick Question, at around the 19:50 mark when you copy/paste,
    it automatically formats all the variables for you and changes the width to height etc..
    Is that a setting? is that an extension?

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety

      I think I am just using the default "format on save" behavior in VSCode, for more: czcams.com/play/PLRqwX-V7Uu6Zu_uqEA6NqhLzKLACwU74X.html

    • @michazajczyk1554
      @michazajczyk1554 Pƙed rokem

      It was not automatically changed while saving, but only postprocessed, and sped up by Dan.
      He removes repeatable things in post production so it looked like it was changed with some kind of tool/linter but it wasn't :)

  • @peoplethesedaysberetarded
    @peoplethesedaysberetarded Pƙed 5 lety +5

    Ah, Craig Reynolds finally shows up in the channel.

  • @gameglitcher
    @gameglitcher Pƙed 4 lety

    Every time your points roll over the edge they fall out of the perception. This was most noticeable during separation and your slider testing at the end, when you have some boids cross the edge and then just yeet off on their own.

  • @MrNosugarcoating
    @MrNosugarcoating Pƙed 5 lety +1

    Yesss. Back to fun stuff. Lol

  • @ThankYouESM
    @ThankYouESM Pƙed 4 lety +1

    Flocking Awesome!

  • @bluetype8223
    @bluetype8223 Pƙed 5 lety +1

    Imagine how cool a 3d flocking environment with drones would be!

  • @prashanthkumar5987
    @prashanthkumar5987 Pƙed 5 lety +1

    cool video 😁

  • @OonHan
    @OonHan Pƙed 5 lety +8

    Do simulations of whirlpools!

  • @alexanderbuk-swienty7334
    @alexanderbuk-swienty7334 Pƙed 2 lety

    Hi Dan. First of all thanks for all your stuff. I've learned tons from following along. I've improved several things on my own but am kind of stumped on the state/snapshot idea. Anyone have any pointers? Much appreciated.

  • @KenzoArts
    @KenzoArts Pƙed 4 lety

    Hello Daniel! I am a big fan of you, and i would like to know if you have a code challenge where you explain in details the pixels and more specifally on how to do pixel measurement like px to inches.Thanks so much for insight content.

  • @Diotallevi73
    @Diotallevi73 Pƙed rokem +1

    7:03 "How, how, how!" I don't get the reference. Back to Life by Soul 2 Soul?

  • @ricardoespinoza5821
    @ricardoespinoza5821 Pƙed 5 lety

    Does someone know what the line

  • @TidBitOf
    @TidBitOf Pƙed 4 lety

    I don’t program in JavaScript or Processing. I program in Python,C, and R. I still learn so much from these videos though.

  • @arcadegamer6271
    @arcadegamer6271 Pƙed 5 lety +1

    you is good in prgramming!!!

  • @kazian5453
    @kazian5453 Pƙed 3 lety +1

    Hey Dan, I added an avoid collisions method to avoid all the boids from gathering into the same single point, by basically reversing the cohesion method, and only checking and applying the force if any boid is within 8 of any other boid (where distance between boids is less than 8, than apply opposite force). However, I'm running into an interesting bug with the simulation. The edge of the canvas, which we've defined behavior in the edges() method teleports the boid to the other side of the canvas. It is no longer part of the flock group that it was originally in, since this teleportation overwrites it's position, and puts it out of the perception radius of the flock group it was originally in. So if a flock group gets too close to the edge, and just skims it, the edge will cut it into two groups. Those that stayed on the one side, and those that were teleported to the opposite side. Any suggestions on how to fix this?

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 3 lety +1

      Wow, super interesting question! The discord is a great place for this discussion! thecodingtrain.com/discord

  • @malpaca
    @malpaca Pƙed 5 lety

    when I do create vector with some parameter passed into it the console say that position is not a number

  • @Thoracius
    @Thoracius Pƙed 4 lety

    seems like separation should act more strongly on closer boids, not uniformly across the detection radius.

  • @matiasvlevi6647
    @matiasvlevi6647 Pƙed 5 lety +1

    Iv'e been trying to make them rotate (made them in arrows) towards where they want to go but I don't know which vector is their direction.

  • @WildAnimalChannel
    @WildAnimalChannel Pƙed 5 lety +2

    One problem is the perception radius is not wrapped around the edges.

  • @zenglingyuan6439
    @zenglingyuan6439 Pƙed 5 lety

    Hi Daniel... can you talk about some mechanics of how computer works? I'm totally a non-cs student, but sometimes I get confusing when a sketch become slow, why our computer can run a big program but it will get slow for our little sketch?

  • @WildAnimalChannel
    @WildAnimalChannel Pƙed 5 lety +32

    Boid is New York speak for bird. Have you hoid about the boid?

  • @gytiskau1865
    @gytiskau1865 Pƙed 5 lety +2

    This was very interesting, no matter that I understood less then 1/3 of this *programing*. Not complaining or anything. Still loved it!

  • @nhatkhoaphan971
    @nhatkhoaphan971 Pƙed 4 lety

    How can i make the system flocking around a target?

  • @VictorRivarola007
    @VictorRivarola007 Pƙed 4 lety

    38:40 It would be interesting if you covered how to integrate a glade GUI generator with Processing and/or with P5.js (it is available for both Java and Javascript, along with a whole different bunch of other programming languages on any platform).

  • @bradymiclea1705
    @bradymiclea1705 Pƙed rokem

    I need some help if anyone can, my boids space out as expected but the more of them that join a single flock they start slowing down alot and eventually pretty much stop. When i have a fewer amount of them they work perfect but the more i add then their velocities just drop to almost nothing within a minute. Even when i do have a lot if there is a few smaller seperate flocks instead of one big one then it works but when the smaller flocks combine again the boids slow down. I have tried messing with all the values of the three rules and multiplying the forces but nothing works. If i multiply the forces tthen they will be super fast when alone or in small froups but when they combine they still slow down. Sorry for being a little repetitive if you have the time and know whats wrong please help. Thankss!

  • @doctorgraphics
    @doctorgraphics Pƙed rokem

    Could this happen on the Apple 2? That would be awesome!

  • @robertotomas
    @robertotomas Pƙed 4 lety

    Anyone know enough about p5 to know how to bound their movement to a path? (Like, draw a path first with mouse down, then next phase how to position them in the path? How to redraw the path that was drawn in first phase?)

  • @OonHan
    @OonHan Pƙed 5 lety

    Amazing! I am your biggest fan!!!

  • @rnilu86
    @rnilu86 Pƙed 5 lety +4

    Fourier series wave coding? ;)

  • @shinershawn6053
    @shinershawn6053 Pƙed 2 lety

    I like how he always says "from scratch" and then proceeds to use some game and graphics engine

  • @akhs001
    @akhs001 Pƙed 4 lety

    This dot , this dot :) :) Nice song

  • @vixtorocha
    @vixtorocha Pƙed 5 lety

    Dan!!! How do you find these code challeges? I want to attempt them myself!

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety +1

      They get suggested here! github.com/CodingTrain/Rainbow-Topics/issues

  • @danthiel8623
    @danthiel8623 Pƙed 2 lety

    Interesting

  • @zohaibshafique940
    @zohaibshafique940 Pƙed 3 lety

    why in update method , we first update position, then velocity, not other way around

  • @disdis6127
    @disdis6127 Pƙed 3 lety

    How about making a video on steering bhaviours with path finding?

  • @toadfrommariokart64
    @toadfrommariokart64 Pƙed 3 lety

    attaboid!

  • @nickbrighty8882
    @nickbrighty8882 Pƙed 5 lety

    Love the videos, Dan! But I'm new to all this coding stuff, and even though I follow your coding and it all seems to work (using Sublime and Firefox), I have the grey canvas and the white boid... but it doesn't move! I check over the code and it's exactly as in the video, but nothing happens... Where might I be going wrong?!

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety +1

      Would you mind asking at discourse.processing.org/! It's a better platform for Processing and p5.js related code questions. You can share code there easily! Feel free to link from here to your post.

    • @nickbrighty8882
      @nickbrighty8882 Pƙed 5 lety

      @@TheCodingTrain Thank you, I'll give it a try...

  • @xmizz08
    @xmizz08 Pƙed 3 lety

    How do you get the "boid" to avoid you mouse?

  • @mattshnoop
    @mattshnoop Pƙed 5 lety +2

    Hey Dan, I asked this question before, but got no answer. Why do you use VS Code now, instead of Atom? What does it offer that Atom does not? I've just gotten comfortable with Atom thanks to you, but now I'm wondering if I should be using VS Code instead!

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety +9

      To be honest I don't see a clear advantage of one over the other. I do see more of my students using VSCode these days so I wanted to try to learn and get used to it. I don't think you need to worry too much, both will work for all the things I do in my videos!

    • @mattshnoop
      @mattshnoop Pƙed 5 lety

      @@TheCodingTrain Thanks :) I was worried that maybe there was one 'killer feature' of Code I was missing out on.
      Incidentally, this was one of my favourite Coding Challenges so far! Thanks for the great content.

    • @shivamchhetri9893
      @shivamchhetri9893 Pƙed 5 lety +1

      my reason is integrated terminal in VS code.

  • @NatetheAceOfficial
    @NatetheAceOfficial Pƙed 5 lety +9

    Oh man, Boids is fun! I only know it from running simulations in Blender. Very cool to see it in 2D. Could we get this in P3D please!?

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety +2

      I'm hoping a viewer will implement this! (But sure I am happy to make an example.)

  • @sendark001
    @sendark001 Pƙed 5 lety

    How about doing it on the GPU in 3D?

  • @mihaisolomon2893
    @mihaisolomon2893 Pƙed 5 lety

    Whats the name of your VS code font?

  • @denniskwan1906
    @denniskwan1906 Pƙed 5 lety

    @The Coding Train just to ask what editor you're using for this project (as well as all the previous ones)
    Thanks in advance

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety +1

      This workflow series might help! czcams.com/play/PLRqwX-V7Uu6Zu_uqEA6NqhLzKLACwU74X.html

    • @denniskwan1906
      @denniskwan1906 Pƙed 5 lety

      @@TheCodingTrain thanks

  • @RogerKeulen
    @RogerKeulen Pƙed 5 lety +6

    Your "dist()" distance function does not work at the border of the screen. x1=639, x2=1 distance should be 640-639+1=2

  • @JGTooooah
    @JGTooooah Pƙed 5 lety

    At 20:45 they're all slowing down because the average of an array of pseudorandomly generated vectors is about zero.

  • @jacobbeitner8796
    @jacobbeitner8796 Pƙed 4 lety

    You should have let them see everyone else in the flock, but be attracted to closer ones more than ones that are farther away

    • @ccoodduu
      @ccoodduu Pƙed 3 lety

      That would be really slow

  • @oxrock2k1
    @oxrock2k1 Pƙed 5 lety +1

    I created a 3d implementation with bluejays in Unity that allows you to adjust relevant values in real time. You can play it here: oxrock.itch.io/flocking-boids I also posted the scripts on github for any who are interested: github.com/oxrock/BOIDS
    In my simulation the boids are incentivised to turn back when they reach the edges instead of teleporting around to the other side. This eliminates the need to monitor for boids that have already teleported but should theoretically still be in range while adding to the number of group maneuvers emerging from being constrained to a predetermined space.

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety

      Wow! This is amazing and thrilling to see! Would you mind adding a link here?
      github.com/CodingTrain/website/wiki/Community-Contributions-Guide

    • @oxrock2k1
      @oxrock2k1 Pƙed 5 lety

      @@TheCodingTrain Created the pull request. Glad you like it. :)

  • @x_czt
    @x_czt Pƙed rokem

    Still didn't get it what is CreateVector() ?

  • @DEVDerr
    @DEVDerr Pƙed 5 lety

    9:58 Why not a foreach? It's much simplier

  • @Xnichfrytk
    @Xnichfrytk Pƙed 5 lety +1

    33:56 are we really not addressing how the flock formed a crystal/lattice ????

  • @niranjannidhi
    @niranjannidhi Pƙed 5 lety +1

    19:54 nice

  • @wesleythomas6858
    @wesleythomas6858 Pƙed 5 lety +1

    What the flock!

  • @lilboat8421
    @lilboat8421 Pƙed 5 lety

    Hi, I’m a graphic design student trying to expand my knowledge and these videos are an amazing help! Is there a way you can implement the accelerometer for cool interactions with moving your phone to move a 3D object for example in p5 js? That would be awesome

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety

      Yes, check out the acceleration events! p5js.org/reference/

    • @lilboat8421
      @lilboat8421 Pƙed 5 lety

      The Coding Train i still came away a bit confused.. could you make a video about how to include the physics engine with the accelerometer? Thanks

  • @Flackon
    @Flackon Pƙed 5 lety

    IT would have been nice to draw them as pointed triagles though. I wonder what the logic for that looks like

    • @TheCodingTrain
      @TheCodingTrain  Pƙed 5 lety +1

      You can find that code at github.com/shiffman/The-Nature-of-Code-Examples-p5.js/tree/master/chp06_agents/NOC_6_09_Flocking