Coding Challenge 124: Flocking Simulation

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024

ความคิดเห็น • 253

  • @MasterHigure
    @MasterHigure 5 ปีที่แล้ว +182

    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  5 ปีที่แล้ว +51

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

    • @VladSandu79
      @VladSandu79 5 ปีที่แล้ว +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 5 ปีที่แล้ว +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 5 ปีที่แล้ว +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 5 ปีที่แล้ว +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 5 ปีที่แล้ว +194

    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

    • @toastyPredicament
      @toastyPredicament 2 ปีที่แล้ว

      Potatoes

    • @EzraClintoc
      @EzraClintoc 5 หลายเดือนก่อน

      @@toastyPredicament potaTOES are good

  • @abdimalikosman559
    @abdimalikosman559 5 ปีที่แล้ว +28

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

  • @ezequiel9055
    @ezequiel9055 2 ปีที่แล้ว +9

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

  • @KristianPedersen
    @KristianPedersen 5 ปีที่แล้ว +63

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

    • @TheCodingTrain
      @TheCodingTrain  5 ปีที่แล้ว +48

      This from the the creator of the THIS DOT song everyone!!!! ❤🙏❤🙏❤🙏❤🙏❤🙏❤🙏❤

  • @sayanghosh6996
    @sayanghosh6996 5 ปีที่แล้ว +122

    19:53 Dan.exe has stopped working

    • @kushagra64
      @kushagra64 3 ปีที่แล้ว +2

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

  • @BulletProofCupid7
    @BulletProofCupid7 2 ปีที่แล้ว +27

    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 :)!

  • @zaynbaig3157
    @zaynbaig3157 4 ปีที่แล้ว +8

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

  • @gid9551
    @gid9551 5 ปีที่แล้ว +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!

  • @echoes6092
    @echoes6092 5 ปีที่แล้ว +8

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

  • @lopa8519
    @lopa8519 5 ปีที่แล้ว +4

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

  • @MrPeloseco
    @MrPeloseco 5 ปีที่แล้ว +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!!

  • @Dgiulian
    @Dgiulian 5 ปีที่แล้ว +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

  • @toastrecon
    @toastrecon 5 ปีที่แล้ว +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 ปีที่แล้ว +1

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

  • @SMujiH
    @SMujiH 5 ปีที่แล้ว +50

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

    • @retrodragon2249
      @retrodragon2249 4 ปีที่แล้ว +2

      of liquid crystal.

    • @nirmalmattmusic3993
      @nirmalmattmusic3993 3 ปีที่แล้ว +1

      He's Bob Ross but of coding

    • @fedos
      @fedos 3 ปีที่แล้ว +1

      There are no bugs, only happy accidents.

  • @BorisJensen
    @BorisJensen ปีที่แล้ว +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

  • @tylerhorton9807
    @tylerhorton9807 4 ปีที่แล้ว +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..

  • @sindreeidskrem2137
    @sindreeidskrem2137 5 ปีที่แล้ว +18

    🎵 My vector brings all the local boids to my local position!🎶

  • @atrumluminarium
    @atrumluminarium 5 ปีที่แล้ว +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

  • @TheFinagle
    @TheFinagle 3 ปีที่แล้ว +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).

  • @UweEichel
    @UweEichel 5 ปีที่แล้ว +2

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

  • @pyrookil480
    @pyrookil480 5 ปีที่แล้ว +61

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

    • @ArnoldsKtm
      @ArnoldsKtm 5 ปีที่แล้ว +4

      One round boi

    • @Wherrimy
      @Wherrimy 5 ปีที่แล้ว

      Mah BOI !!

  • @kodefattern
    @kodefattern 5 ปีที่แล้ว +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 5 ปีที่แล้ว +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  5 ปีที่แล้ว +5

      Yes, and then we should collaborate on a music video!!! 🎵❤

    • @kodefattern
      @kodefattern 5 ปีที่แล้ว +2

      @@TheCodingTrain deal!

    • @GodofChookie
      @GodofChookie 5 ปีที่แล้ว +1

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

  • @kevnar
    @kevnar 5 ปีที่แล้ว +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.

  • @Chayat0freak
    @Chayat0freak 5 ปีที่แล้ว +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

  • @badunius_code
    @badunius_code 2 ปีที่แล้ว +2

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

  • @zanejohns777
    @zanejohns777 5 ปีที่แล้ว +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.

  • @RedHair651
    @RedHair651 ปีที่แล้ว

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

  • @TonyZhang01
    @TonyZhang01 5 ปีที่แล้ว +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

  • @LucaPrn
    @LucaPrn 5 ปีที่แล้ว +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 :)

  • @michaelwalker1013
    @michaelwalker1013 5 ปีที่แล้ว +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  5 ปีที่แล้ว

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

    • @michazajczyk1554
      @michazajczyk1554 2 ปีที่แล้ว

      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 :)

  • @6Pope9
    @6Pope9 8 หลายเดือนก่อน

    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.

  • @Eman6240
    @Eman6240 4 ปีที่แล้ว

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

  • @monocore
    @monocore ปีที่แล้ว

    Ive learnt VEX with your tutorials. Youre amazing.

  • @TiffanyNg100
    @TiffanyNg100 3 ปีที่แล้ว

    your energy never disaapoiint me

  • @andrasfauszt1693
    @andrasfauszt1693 5 ปีที่แล้ว +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.

  • @pythonexploits8364
    @pythonexploits8364 5 ปีที่แล้ว +2

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

  • @alexlindsay9002
    @alexlindsay9002 5 ปีที่แล้ว +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...

  • @twinpotatoes5513
    @twinpotatoes5513 5 ปีที่แล้ว +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

  • @Diotallevi73
    @Diotallevi73 ปีที่แล้ว +1

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

  • @WildAnimalChannel
    @WildAnimalChannel 5 ปีที่แล้ว +32

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

    • @johnjackson9767
      @johnjackson9767 5 ปีที่แล้ว +1

      Wild Animal Channel 'You sing like a boid'.

  • @ghghvfugx_gh35
    @ghghvfugx_gh35 ปีที่แล้ว

    this man is fantastic

  • @ThankYouESM
    @ThankYouESM 4 ปีที่แล้ว +1

    Flocking Awesome!

  • @lizabeti3457
    @lizabeti3457 5 ปีที่แล้ว +5

    Awee making that without lunch You’re crazy 😂

  • @djsyntic
    @djsyntic 2 ปีที่แล้ว +2

    Pausing at 13:03, personally, I would have left align generic and aligned to all boids in the list that it receives, and had perception be it's own thing that returns a list of boids. So then you would call it with align(perception(AllBoids))
    This for 2 reasons: 1) Other things you might want the boid to do may also require the boids to respond to the boids it sees around it, so it saves you from need to recode the perception for each one. And 2) If you want to later change how the boids see the world, it's all in one nice area to be adjusted.

  • @bluetype8223
    @bluetype8223 5 ปีที่แล้ว +1

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

  • @tomd8168
    @tomd8168 5 ปีที่แล้ว

    That was really awesome, thanks!

  • @oxrock2k1
    @oxrock2k1 5 ปีที่แล้ว +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  5 ปีที่แล้ว

      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 5 ปีที่แล้ว

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

  • @emanouda9797
    @emanouda9797 3 ปีที่แล้ว

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

  • @OonHan
    @OonHan 5 ปีที่แล้ว +8

    Do simulations of whirlpools!

  • @shinershawn6053
    @shinershawn6053 3 ปีที่แล้ว

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

    • @pritamdavis
      @pritamdavis 2 ปีที่แล้ว

      @Justin batchelar agreed

  • @kevnar
    @kevnar 5 ปีที่แล้ว +1

    float GetDistWrap(float x1, float y1, float x2, float y2) {
    // A distance function for simulations with toroidal screen wrapping
    // Places a simulated x2, y2 beyond the edge of the screen
    // returns the distance taking into account screen wrapping
    // if on-screen distance is lower, returns that

    float fxDiff;
    float fyDiff;
    float xDiff1 = Math.abs(x1 - x2);
    float xDiff2 = Math.abs(x1 - (x2 - width));
    if (xDiff1 < xDiff2) {
    fxDiff = xDiff1;
    } else {
    fxDiff = xDiff2;
    }
    float yDiff1 = Math.abs(y1 - y2);
    float yDiff2 = Math.abs(y1 - (y2 - height));
    if (yDiff1 < yDiff2) {
    fyDiff = yDiff1;
    } else {
    fyDiff = yDiff2;
    }
    return (float)Math.sqrt((fxDiff * fxDiff) + (fyDiff * fyDiff));
    }

  • @SirBartolomew
    @SirBartolomew 5 ปีที่แล้ว +3

    They're slowing down because you're averaging the speed vectors. Since they start out random, by the law of large numbers with many boids it tends to 0.

  • @gameglitcher
    @gameglitcher 4 ปีที่แล้ว

    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.

  • @TidBitOf
    @TidBitOf 4 ปีที่แล้ว

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

  • @johanrojassoderman5590
    @johanrojassoderman5590 หลายเดือนก่อน

    4:35 jesus what a jumpscare. I think I prefer header files, lol.

  • @kazian5453
    @kazian5453 3 ปีที่แล้ว +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  3 ปีที่แล้ว +1

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

  • @RogerKeulen
    @RogerKeulen 5 ปีที่แล้ว +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

  • @angelcaru
    @angelcaru 4 ปีที่แล้ว +2

    Visual Studio Code auto-completes this. IFF you press TAB

  • @gytiskau1865
    @gytiskau1865 5 ปีที่แล้ว +2

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

  • @Thoracius
    @Thoracius 4 ปีที่แล้ว

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

  • @WildAnimalChannel
    @WildAnimalChannel 5 ปีที่แล้ว +2

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

  • @arcadegamer6271
    @arcadegamer6271 5 ปีที่แล้ว +1

    you is good in prgramming!!!

  • @MrNosugarcoating
    @MrNosugarcoating 5 ปีที่แล้ว +1

    Yesss. Back to fun stuff. Lol

  • @NatetheAceOfficial
    @NatetheAceOfficial 5 ปีที่แล้ว +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  5 ปีที่แล้ว +2

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

  • @mattshnoop
    @mattshnoop 5 ปีที่แล้ว +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  5 ปีที่แล้ว +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 5 ปีที่แล้ว

      @@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 5 ปีที่แล้ว +1

      my reason is integrated terminal in VS code.

  • @VictorRivarola007
    @VictorRivarola007 4 ปีที่แล้ว

    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).

  • @julianavar3836
    @julianavar3836 3 ปีที่แล้ว +1

    19:53 width width x x y y y y x x x x x width width ... alright

  • @matiasvlevi6647
    @matiasvlevi6647 5 ปีที่แล้ว +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.

  • @KenzoArts
    @KenzoArts 4 ปีที่แล้ว

    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.

  • @alexanderbuk-swienty7334
    @alexanderbuk-swienty7334 2 ปีที่แล้ว

    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.

  • @rnilu86
    @rnilu86 5 ปีที่แล้ว +4

    Fourier series wave coding? ;)

  • @Xnichfrytk
    @Xnichfrytk 5 ปีที่แล้ว +1

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

  • @Sccarlettex
    @Sccarlettex 5 ปีที่แล้ว +3

    I promise there will come a time in which I’ll understand half of what he did in this video

    • @TheCodingTrain
      @TheCodingTrain  5 ปีที่แล้ว +3

      I believe in you!

    • @Sccarlettex
      @Sccarlettex 5 ปีที่แล้ว +1

      The Coding Train aw thank you!

  • @yannmassard3970
    @yannmassard3970 ปีที่แล้ว

    hello, you can do the flocking alg by referencing the 7 closets boids around, wich allows avoidance to feel more natural. According to reseaches, birds and fishes follow 3 rules to flock : 1 align speed with 7 boids- 2 If one of the 7 changes direction, you change -3 avoid getting too close to any boid among those 7. I saw a documentary about it 17 years ago and reproduced it back then. Works like a charm, and can handle a shit ton of birds. In order to optimize the distance calculation between boids (to avoid square loops ) you can use a grid space alg. Oh and something else, bird vision that flock (like pigeons) is almost 300d horizontally and 150 v, so making a spherical perception isnt going to cause any non natural behavior, the V shape has nothing to do with vision, they fly in V shape because of motivation, they always follow someone, like cyclists in line, that s why they actually rotate their positions over time.

  • @zenglingyuan6439
    @zenglingyuan6439 5 ปีที่แล้ว

    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?

  • @doctorgraphics
    @doctorgraphics ปีที่แล้ว

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

  • @toastyPredicament
    @toastyPredicament 2 ปีที่แล้ว

    I will be here forever. I will be forever. His forever

  • @prashanthkumar5987
    @prashanthkumar5987 5 ปีที่แล้ว +1

    cool video 😁

  • @bradymiclea1705
    @bradymiclea1705 ปีที่แล้ว

    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!

  • @dx8pi6o48
    @dx8pi6o48 2 ปีที่แล้ว

    Does this code still work with current versions of javascript? I copied your code as the video went on but my boids just refuse to align themselves based on the boids around them.

    • @dx8pi6o48
      @dx8pi6o48 2 ปีที่แล้ว +1

      Nevermind! I placed an extra 'c' in this.acceleration. Fixed now!

  • @grepgrok8735
    @grepgrok8735 3 ปีที่แล้ว

    40:13 and now the boids are officially predators

  • @niranjannidhi
    @niranjannidhi 5 ปีที่แล้ว +1

    19:54 nice

  • @toastyPredicament
    @toastyPredicament 2 ปีที่แล้ว

    This the Voidlocke.

  • @wesleythomas6858
    @wesleythomas6858 5 ปีที่แล้ว +1

    What the flock!

  • @A_Lesser_Man
    @A_Lesser_Man 4 ปีที่แล้ว +3

    @Dan - I am really liking this boid stuff! super neat. love that i can do rudimentary AI. Your style is definitely comical and makes this learning thing much more fun, for sure! Hopefully with your teachings I can build a Boid sim worthy of discussion.
    On another note, I've got a small problem with something. My boids go offscreen, and won't come back (unless i do a if (this.position.x < -200) { this.position.x = width/2; } etc.). Would you, or anyone, really be willing to take a peak and perhaps point out where i've gone wrong? i'm not asking for a solution to the issue, but a pointer in the right direction, really. all of the code lives at night-stand.ca/boids/ the code in question is in the "boid.js" file. i hope it's easy to read (i try to comment, and make it easy). The three main functions are there - separation, alignment, and cohesion. added in "boundaries()" function (to replace wraparound function) ... and now boids will sometimes just fly off ... and not return without a check. Please help...
    press 3 to get the Boids moving fast. The issue happens fastest that way. Boids will "die" and will be "born", too. Press B then A to see LOADS of info about each and every Boid, perhaps that can help us...?

  • @DEVDerr
    @DEVDerr 5 ปีที่แล้ว

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

  • @JohnSlipper
    @JohnSlipper ปีที่แล้ว

    Great video! You could catch your syntax errors earlier in VS Code (like you do in Processing) using a JavaScript linter. I thought VS Code did it by default but you might need something like the ESLint extension installed.
    ...ok now I'm just realising this video is 3 years old so probably not the most useful comment now 😆

  • @disdis6127
    @disdis6127 3 ปีที่แล้ว

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

  • @lilboat8421
    @lilboat8421 5 ปีที่แล้ว

    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  5 ปีที่แล้ว

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

    • @lilboat8421
      @lilboat8421 5 ปีที่แล้ว

      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

  • @danthiel8623
    @danthiel8623 2 ปีที่แล้ว

    Interesting

  • @toastyPredicament
    @toastyPredicament 2 ปีที่แล้ว

    Pls be ok

  • @hongvicodes
    @hongvicodes 5 ปีที่แล้ว

    @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  5 ปีที่แล้ว +1

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

    • @hongvicodes
      @hongvicodes 5 ปีที่แล้ว

      @@TheCodingTrain thanks

  • @89elmonster
    @89elmonster 5 ปีที่แล้ว

    I have a challenge that will literally take you seconds to do(since I don't have Twitter). You know that classic DVD screen where it bounces across the screen? Do that but with a picture of a cat! It should take you no more than 30 minutes!

  • @Flackon
    @Flackon 5 ปีที่แล้ว

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

    • @TheCodingTrain
      @TheCodingTrain  5 ปีที่แล้ว +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

  • @akhs001
    @akhs001 4 ปีที่แล้ว

    This dot , this dot :) :) Nice song

  • @toadfrommariokart64
    @toadfrommariokart64 3 ปีที่แล้ว

    attaboid!

  • @onebeartoe
    @onebeartoe 11 หลายเดือนก่อน

    Flock!

  • @sujals7108
    @sujals7108 5 ปีที่แล้ว

    Please do vortex simulation

  • @hugurs2396
    @hugurs2396 3 ปีที่แล้ว +1

    What the flock!?

    • @napalm5
      @napalm5 2 ปีที่แล้ว +2

      Get the flock outta here (via seperation)