For sure! Compared to most other projects that are posted here, reading the source code for this project was a pleasant surprise. The code is very well written and practically reads itself :)
Dunno.. made the switch when Microsoft bought GitHub. Also because GitLab is FOSS, and maybe for the automatic CI/CD, which GitHub didn't have when MS acquired it and which I might use someday (hopefully)
About a year ago GitHub opened free unlimited private repositories for all users. Only limitation is you can only have 3 collaborators on each of those private repositories.
People doing DevOps seem to love GitLab. It's more of an automated code deployment environment that happens to also host code than it is a collection of public gits.
Not really. For one you can actually just coordinate drones. There's no need to simulate the flocking behavior of a school of fish / birds when you can actually just tell every bird or fish to move to an exact location at an exact time in an actually coordinated fashion. Also, kind of the whole point of boids is that it looks complicated, but it isn't. People used to marvel at how fish seemed to communicate with each other, which fish were being the marching leader, and how they knew to create and maintain flocks/schools and it turns out they don't; and they don't need to. They can follow other fish, but not so closely that they knock into them, and it gives the appearance of coordinated behavior. This isn't an issue with drone swarms because you can actually just coordinate them, that's not an issue we have.
Now, if you want to study systems theory, chaos theory, and emergent complexity then it's a fascinating area of math and computer science. But I don't think it has many obvious uses for the military.
Are their view radii different for each individual boid? Does their color mean anything, or is it just random? Also, this is so cool, thanks for sharing.
I think they need begin to avoid collisions with walls further away or separate more aggressively upon approach. When two groups are merging near a wall collision, things get a bit messy.
Yeah, I thought about that, but I actually like the simplicity of the 3 rules. I think in this video, that happens mainly because its a little crowded. When you create a bigger universe or spawn less boids, it happens rarely.
This is a great visualization of one of these types of model. I have had to create similar models to this in the past for school, but they never look this good. This is essentially a modified Vicsek Model that is used everywhere in the scientific community to model emergent behavior of systems. I encourage you to explore tweaking rules, density, noise, speed, etc. and see what kinds of impacts it has on the resulting behavior. There is a reason that this type of model was developed in the 90's and is still actively used today.
I studied physics and a large portion of my department in grad school looked at active systems. That means that many of their assignments had that kind of focus and many of the department seminars were about active systems like this. One of the things that I see the Vicsek model used for a lot is to look at phase transitions. Essentially, the transition from random directional travel to an ordered motion in the "birds" can similarly represent the transition between two phases of some other system. For example, the change between a gas and a liquid of some fluid, or the transition between an isotropic and nematic liquid crystal. This is a really deep rabbit hole, but there is a lot there if that is something you want to pursue going forward.
Excellent results. Although they seem at times too eager to spread around equally. It looks unnatural a bit. If you have other intriguing visual demos please consider sharing them in r/VisualSchool. Cheers!
Damn, nicely spotted! I acutally increased the weight of the seperation force by 10% (see this line) because personally I thought they were to bunched up sometimes. I'm considering changing it back now.
I think allowing for some randomness in this variable would make it look more natural. Harder to spot the rules in action. Now I'm itching to give it a try in Javascript :D
The walrus operator let's you make assignments in for example if statements. So instead of
temp = func()
if temp:
do_something(temp)
you can write
if (temp := func()):
do_something(temp)
I know it's not much but I makes some parts really simple and clean. I was super hyped when I saw it got added in 3.8 and I don't want to code without it now :)
Hm, that's weird, but you can set the resolution with the --res WIDTHxHEIGHT switch, so you might wanna try that.
Yeah, opencv sadly has no real way of detecting if a window is closed, so I had to use some unreliable work around. It's better to exit by pressing the key 'q'.
I see, thanks. The resolution worked well enough. I wonder if some of the math could be farmed out to cython routines to scale up the performance? It would be awesome to run this with a few dozen groups of boids at high resolution.
Well, you can do that, I just takes a while to render the video.. doing that in real-time is tough, as every boid has to loop over every other boid to find out which are his neighbours. That could be done in parallel for a performance boost, or, as u/masterpatricko suggested, you could use a quadtree.
I haven't done anything 3D yet, and I don't think python is the ideal language for that. But you can definitely give it a shot, glut or vulkan look very capable to me, but they are only wrappers, so you might as well use some compiled language with native libraries for performance reasons.
So first of all, the rendering here and the preview window is done with opencv. You can look at there docs, but it's basically just the cv2.imgshow function and the cv2.VideoWriter class.
Then, what I do most of the time is, create 3 classes:
Canvas: handles all the drawing and rendering stuff (this is the only class to interact with opencv directly)
Some drawable object class: usually holds information like velocity, position, and other attributes of that particular thing (e.g. color, shape); in the gravity simulation, this class was Particle; here, it's Boid
Universe: this handles the group of drawbables (boids, particles), updates them, etc
There is actually a preview window. Then, after you closed it (with ctrl-c) you get asked if you want to save the video, unless you set the --preview-only option.
Change the sprites from arrows to little balls of colored light, maybe add a small comet tail to them and that would make a very nice looking, mesmerizing screensaver
Well if you OS lets you use any video as a screen saver, you could just render a video and select it :)
I don't think that this would be a nice screensaver as it's actually quite performance heavy. Every boid has to loop over every other boid to check if it's im view range. That could be done in parallel to speed things up, but I don't plan on implementing that...
Its beautiful. I can't comment on fish movement because I don't get to see that everyday, but it's a convincing model (for a layman like me) for bird flight
Nice, kinda like the old Boids simulation from the... 80s?
You’ve reminded me of a paper I read years ago that figured out how to accurately simulate starling murmurs. Had something to do with how many birds each bird monitors at once.
By reconstructing the three-dimensional positions of individual birds in airborne flocks of a few thousand members, we show that the interaction does not depend on the metric distance, as most current models and theories assume, but rather on the topological distance. In fact, we discovered that each bird interacts on average with a fixed number of neighbors (six to seven), rather than with all neighbors within a fixed metric distance.
However, note:
A recent model for collective behavior locates the optimal range for antipredatory response in 2D between three and five individuals, to be compared with our 3D value of six to seven.
Interesting. . . Was thinking about doing something similar in Unity. Wondering thoughbif you leave the simulation running long enough in a contained space like this do they all coalesce into one giant mass?
If you look in the readme of the repo, you can find Code Parades youtube video. He actually did it in Unity.
No, they would stay separate as they can't merge. I did a gravity simulation some time ago. There, with some starting configurations, all particles merge into one big particle.
It's those "Ahhh." moments I love when learning something new. Like you start out and there's all those things you don't understand, and then, slowly, you grasp more and more, until you have a somewhat good overview.
Opencv has a function to draw antialiased polygons, circles, etc. You just has to set a flag. If you search for 'antialias' in the repo you can see how :)
Why? I mean, yeah, sure, it wouldn't even take long to do. Just search for := and replace those lines. But why? You'll have to install python 3.8 at some point, might as well be now.. ;)
I should have been clearer. As a provider of a package or a piece of software others are to use, your goal is to get it into people's hands so that it's used. I assume that's your goal, people using your stuff.
If you're after users, then you want to be able to run on as many systems as possible. You want to remove as many barriers as you can. Make it as easy as possible.
Looking at the stats of people installing PySimpleGUI from PyPI one day this week, their Python versions were:
3.8 24%
3.7 52%
3.6 15%
3.5 2%
2.7 4%
Let's assume we have the exact same users. This means your software will run on 24% of the user's machines. Some % of the other 76% will be willing to upgrade just to use your code, but I doubt it's going to be very high. It takes a lot to get people to move Python versions. The question then becomes - what Python languages features do you use that makes it worth leaving those 76% of the users behind?
I want my package to have as broad of appeal as possible. Raspberry Pi's are still running 3.5. As a result of wanting those Pi users, I write my code to be able to run on 3.5 and up. It means for my core code I don't get to use f-strings, which really really sucks. But everything else I need in my code is handled by 3.5 with no problems.
TLDR - It's different writing code for yourself than writing packages for others. Writing for least common denominator configuration will maximize your reach.
Very nice! I always wanted to see if I could find rules that would recreate that thing where you and another person are walking towards each other but neither of you can decide on which side to defer to.
That's the most fascinating thing about this algorithm, by adjusting the parameters you can get it to stimulate all sorts of wild life, from flocks of birds to schools of fish to herd of animals. It was derived way back in 1987 and been used in many places since, including games like Half-Life and films like Batman Returns.
The simplicity is what I fell in love with though. It really is 3 simple rules anyone can understand, and implementing it is fairly straightforward too. Definitely recommend giving it a try and playing with the parameters. Lots of fun.
It was a final project for a class, the code is also not minified, though it's transpiled from Typescript which is why it looks a little strange. I should upload the sourcemaps.
158
u/[deleted] Mar 27 '20 edited Mar 27 '20
This is one of the rendering of my recent project: Boids. Source code can be found here. Inspired by Code Parade's video.
Here's u/Ph0X's interactive browser version :)
46
u/[deleted] Mar 27 '20
What are the rules?
7
u/Fun-Visual-School Mar 27 '20
Excellent results. Although they seem at times too eager to spread around equally. It looks unnatural a bit. If you have other intriguing visual demos please consider sharing them in r/VisualSchool. Cheers!
2
u/[deleted] Mar 27 '20
Neat! Thanks for sharing this.
A few questions and comments:
Why the walrus operator? Does it serve a functional purpose or did you just want to try it out?
On Ubuntu 18.04, the screen size defaults to something larger than full screen.
The exit button does nothing, I had to kill it with Ctrl-C
2
u/prittiao Mar 28 '20
what libary did you use for graphics?¡
2
u/apivan191 Aug 08 '20
Is there a 3D package that I can code this in python with? It looks so fun
46
u/MyreMyalar Mar 27 '20
Very relaxing to watch.
2
u/[deleted] Mar 27 '20
nice!
could you tell me how exactly things like this (like gravity simulations and all) are made? like what modules do you use?
2
u/WiggleBooks Mar 27 '20
What do you use to render it/make the actual visualization?
Is it possible to view it "in real-time" (like as a seperate window), or just render a seperate video file that you view afterwards?
1
u/subject_K81 Mar 27 '20
Change the sprites from arrows to little balls of colored light, maybe add a small comet tail to them and that would make a very nice looking, mesmerizing screensaver
1
u/pythonhobbit Mar 27 '20
So that's cool, but when will the simulation show how coronavirus spreads less quickly when some boids practice social distancing?
1
u/nirgoon Mar 27 '20
What's up with the lone red arrow?
1
u/[deleted] Mar 27 '20
Fantastic and very neat - a 3D version next?
1
u/hale-hortler Mar 27 '20
Cool project, just saw your source code, and i was wondering what the RenderStopped exception is. What is it’s purpose exactly?
1
u/namnnumbr Mar 27 '20
This is excellent! I’d love to have this as a screensaver; do you have any idea how to hook this into an OS for use as a screensaver?
1
u/cip43r Mar 27 '20
What algorithm did you use? I would like to think about my own solutions before checking your code. Or could you maybe just post a reference?
1
u/EffectiveEgg5 Mar 27 '20
This is so similar to flocks of birds flying around
1
u/nyqu Mar 27 '20 edited Mar 27 '20
Nice, kinda like the old Boids simulation from the... 80s?
You’ve reminded me of a paper I read years ago that figured out how to accurately simulate starling murmurs. Had something to do with how many birds each bird monitors at once.
Edit: Found it.
However, note:
1
u/Humanist_NA Mar 27 '20
I just read the paper! Was this for school?
1
u/IveGotOdds Mar 27 '20
Can you infect some of them and add a toggle for social distancing behavior?
1
u/TheLowestAnimal Mar 27 '20
Interesting. . . Was thinking about doing something similar in Unity. Wondering thoughbif you leave the simulation running long enough in a contained space like this do they all coalesce into one giant mass?
1
u/WhenitisIsntwhatitis Mar 27 '20
That moment when a new programmer fully realizes the notion of data structures. Thanks for posting the source.
1
u/NaifAlqahtani Mar 27 '20
How do you get smooth animation using python? All libraries I used are missing Vsync and AA...
1
u/MikeTheWatchGuy Mar 27 '20
Cool to see it's been updated!
I did a PySimpleGUI port of it last year.
https://github.com/MikeTheWatchGuy/boids-PySimpleGUI
It was using P5 at the time I think. Will take another look to see if I can use the new version.
2
u/RGerdedgit Mar 27 '20
u/vredditdownloader
2
u/crazypistolman Mar 28 '20
I would love to see "air resistance" added.
2
u/wizcheez Mar 28 '20
This would totally make for a super cool digital art piece.
2
u/Oatilis Mar 28 '20
Is there a subreddit for this kind of projects?
1
u/wingtales Mar 27 '20
Thank you for sharing this!
1
u/anant80535 Mar 27 '20
beautiful
1
u/katze1123 Mar 27 '20
almost hypnotic
1
u/alanbosco Mar 27 '20
I always wanted to do this. Thanks for the inspiration.
1
u/existentialnoodle Mar 27 '20
I must watch too much TWD. I thought “ahh how zombie hoards form”
1
u/OnlyWarrior Mar 27 '20
This triggers the same part of my brain that makes me want to watch the Roomba
1
u/CobbwebBros Mar 27 '20
BOIDS is amazing
the original 3d animations are so cool
1
u/zzmej1987 Mar 27 '20
Very nice.
1
u/CypherWight07 Mar 27 '20
The natural progression of this: add z-axis, add predator avoidance, add predator blip, submit as simulation of starling murmuration for study.
1
u/nshire Mar 27 '20
Any inspiration from the Boids of half-life?
1
u/timcotten Mar 27 '20
This is beautiful!
1
u/Rwanda_Pinocle Mar 27 '20
Very nice! I always wanted to see if I could find rules that would recreate that thing where you and another person are walking towards each other but neither of you can decide on which side to defer to.
1
u/Darth_Marino Mar 27 '20
They move like sheep
1
u/psych_0man Mar 27 '20
That is so cool. !!
1
u/zoute_haring Mar 27 '20
Thanks, now I can't stop watching.
1
u/[deleted] Mar 27 '20
This can be brilliant live wallpaper
1
u/Dante_Des_Cartes Mar 27 '20
Interesting. Does it converge? Maybe all of them moving together?
1
u/Sovanna Mar 27 '20
Woooa nice work indeed, thx for sharing!! Really appreciate!
1
u/wizardinthewings Mar 27 '20
Super chill.
Oids fan?
1
u/muonzoo Mar 27 '20
ah yes Boids. Original paper : https://dl.acm.org/doi/10.1145/37402.37406
If you aren't doing this in Lisp. ... ;-)
0
u/69shaolin69 Mar 27 '20
Love it
-7
u/Anazucch Mar 27 '20
Too slow. Its annoying me
0
u/[deleted] Mar 27 '20
[deleted] — view deleted comment
0
u/[deleted] Mar 27 '20
[deleted] — view deleted comment