CodeCr4fter
CodeCr4fter
  • 33
  • 20 791
I Coded an ANT COLONY in Python… You Won’t Believe How They Behave!
If you enjoyed the video, please leave a like, subscribe and comment to help me grow my channel! :))
I created a repository since some of you are asking for the code. Sorry if the code is messy ;)
github.com/CodeCr4fter/ant_simulation
Music tracks:
Cinematic by Aylex
Source: freetouse.com/music
Royalty Free Music for Video (Safe)
Pure Dream by Kashia
Source: freetouse.com/music
Background Music for Videos (Free)
Yellow Flower by Kashia
Source: freetouse.com/music
Background Music for Videos (Free)
Deep Sadness by Kashia
Source: freetouse.com/music
Free Background Music for Videos
Beloved by Kashia
Source: freetouse.com/music
No Copyright Vlog Music for Videos
Not Too Far by Another Kid & MohRiz
Source: freetouse.com/music
Free No Copyright Music Download
Timestamps:
00:00 - Intro
00:36 - Ants
01:13 - First Version of Code
01:35 - First Simulation
01:50 - Ant Behavior Explanation
02:06 - Introducing Pheromones
02:26 - Pheromone Code
02:38 - Following Pheromones
03:06 - Second Simulation (With Pheromones)
03:26 - Improving Code
03:36 - Third Simulation (Pheromones Working Better)
03:50 - Further Changes to Code
04:05 - Fourth Simulation (Much Better Pheromones)
04:20 - Optimizing Code
04:40 - Minor Improvements
05:22 - Spatial Partitioning Explanation
05:50 - Implementing Spatial Partitioning
06:40 - Trying Out Spatial Partitioning
07:12 - Spatial Partitioning Almost Working
07:28 - Fixing Minor Bug
07:38 - Spatial Partitioning Finally Working
07:53 - Some Cool Simulations
08:50 - Performance Comparison Between Versions - 100 Ants
09:30 - Performance Comparison Between Versions - 250 Ants
10:30 - Performance Comparison Between Versions - 500 Ants
11:13 - Final Simulation (The End)
มุมมอง: 10 569

วีดีโอ

Python Decorators Explained in 66 Seconds!
มุมมอง 6121 วันที่ผ่านมา
Music track: Married Life by Aylex Source: freetouse.com/music Music for Video (Free Download)
How to Create Ball Simulation For YouTube Shorts and TikToks in Python!
มุมมอง 2.2Kหลายเดือนก่อน
Leave a like and subscribe if you enjoyed! Music tracks: Beloved by Kashia Take Off by Luke Bergs & Waesto Long Way Home by Kashia Source: freetouse.com/music Free To Use Music for Videos Timestamps: 00:00 Intro 00:10 Coding balls and border 00:33 Explaining and coding collision with border 01:24 First simulation 01:34 Adding gravity 02:07 Coding collisions with other balls 03:02 Improving coll...
How Easily Can You Solve Mazes With Python?
มุมมอง 1642 หลายเดือนก่อน
Leave a like and subscribe if you enjoyed! Music tracks: Pure Dream by Kashia Yellow Flower by Kashia Long Way Home by Kashia Source: freetouse.com/music Free To Use Music for Videos Timestamps: 00:00 Intro 00:23 Generating Mazes 00:33 Generating Mazes - DFS 01:00 Generating Mazes - Wilson's Algorithm 01:18 Generating Mazes - Kruskal's Algorithm 02:05 Solving Mazes 02:22 Solving Mazes - DFS 02:...
Breaking Piano Tiles using Python!
มุมมอง 452 หลายเดือนก่อน
Breaking Piano Tiles using Python!
AI learns to play Fruit Ninja!
มุมมอง 702 หลายเดือนก่อน
AI learns to play Fruit Ninja!
Creating Conway's Game Of Life In Python
มุมมอง 333 หลายเดือนก่อน
Creating Conway's Game Of Life In Python

ความคิดเห็น

  • @NopeNopeNope9124
    @NopeNopeNope9124 15 ชั่วโมงที่ผ่านมา

    Believed everything

  • @peligros13
    @peligros13 วันที่ผ่านมา

    Biggest issue I see with this is not using numpy operations for arrays. Your code is full of for loops that are 100s or 1000s of times slower than vectorized code. I know using classes and objects looks cool but it hurts performance by a lot.

    • @CodeCr4fter
      @CodeCr4fter วันที่ผ่านมา

      Thanks for the feedback! I'll try to improve next time

  • @rechtfrage6003
    @rechtfrage6003 วันที่ผ่านมา

    Already spent hours providing enough food to the ants using my mouse-buttons and mouse-wheels, a pleassure to watch ;-) Interesting that in your first iterations the ants seem to leave a (blue) trail, appearing as lines - where in the later iterations (and when using your code on Guthub) they leave blue dots, have you noticed it as well?

    • @CodeCr4fter
      @CodeCr4fter วันที่ผ่านมา

      That's because in the first version ants leave pheromones every single frame, so they appear as a blue line because they blend together. Later I reduced it to every 7 (I believe) steps.

  • @foofoo17
    @foofoo17 วันที่ผ่านมา

    I coded GoL myself as well using Typescript. It's a nice touch adding the image-to-board feature!

  • @foofoo17
    @foofoo17 วันที่ผ่านมา

    sick

  • @NoenD_io
    @NoenD_io 3 วันที่ผ่านมา

    Can you make a tutorial

    • @CodeCr4fter
      @CodeCr4fter 3 วันที่ผ่านมา

      Hi! Maybe someday, but probably not in the near future. If you need the code, link to my github repository is in the description :)

  • @Bee-eautiful
    @Bee-eautiful 3 วันที่ผ่านมา

    that was a great video, ants are great, and so is coding i'm currently learning python actually, and i already know a bit, so i'll look into this to learn more about how to make great things like it

    • @CodeCr4fter
      @CodeCr4fter 3 วันที่ผ่านมา

      I'm glad you liked it!

  • @rumble_bird
    @rumble_bird 3 วันที่ผ่านมา

    You can rewrite ant logic to compute shader, which can potentially increase the performance to handle millions of them, also, i don't know whether kd tree or octtree can increase performance in comparison to grid, but it worth trying. In regard to ant simulation, maybe adding rival ants or other creatures can create interesting patterns.

    • @CodeCr4fter
      @CodeCr4fter 3 วันที่ผ่านมา

      Thanks for the feedback! I'll make sure to look into the things you mentioned

  • @cybermanne
    @cybermanne 3 วันที่ผ่านมา

    Nice project! If you want any kind of feedback (or constructive criticism) on the video itself I think you should try to modulate your narrating a bit more. As in put some emphasis on some words here and there instead of just sounding so flat. I expect you're reading from a script, and that's the reason your voice never changes much.

    • @CodeCr4fter
      @CodeCr4fter 3 วันที่ผ่านมา

      Thank you! I will make sure to pay attention to modulation next time.

    • @cybermanne
      @cybermanne 3 วันที่ผ่านมา

      @@CodeCr4fter It's just one of those things that could potentially make the videos more appealling to people in general. It's one of those things that gets mentioned alot for public speaking. If your voice sounds the same all the time people tend to have difficulties keeping engaged. I don't think it's that much of a problem for an audience that is already very interested in the subject though.

    • @CodeCr4fter
      @CodeCr4fter 3 วันที่ผ่านมา

      @@cybermanne You're absolutely right. Even if the audience is engaged on its own, improving my speaking skills certainly won't hurt.

  • @playing_dark2553
    @playing_dark2553 3 วันที่ผ่านมา

    heyy, i am student and stuck on basic can you help how do i improve

    • @CodeCr4fter
      @CodeCr4fter 3 วันที่ผ่านมา

      Hi! Best advice I can give you is don't stop creating. Create and design things you're interested in and solve problems one by one looking for solutions online. Now that we have LLMs it's easier than ever, but if you're using them avoid mindlessly copying code and try to understand why it works. Don't hesitate to ask for clarifications if you're not sure. Good luck!

  • @marcelbricman
    @marcelbricman 3 วันที่ผ่านมา

    it needs terrain and obstacles! ants could also drop food and of course there will need to be epic battles against other colonies ;)

    • @CodeCr4fter
      @CodeCr4fter 3 วันที่ผ่านมา

      Thanks for the feedback!

  • @GamePlay-pl2nv
    @GamePlay-pl2nv 4 วันที่ผ่านมา

    great video but please focus on the code part more

    • @CodeCr4fter
      @CodeCr4fter 4 วันที่ผ่านมา

      I'm glad you liked it! Do you mean that I should explain the code in more detail?

    • @GamePlay-pl2nv
      @GamePlay-pl2nv 4 วันที่ผ่านมา

      @@CodeCr4fter yes, this video was a lot better than other videos on your channel,create something new and tell us how you did it step by step, tanks

    • @CodeCr4fter
      @CodeCr4fter 4 วันที่ผ่านมา

      I'm happy to hear that because it took quite some time to create it :) Thank you for your feedback!

    • @GamePlay-pl2nv
      @GamePlay-pl2nv 4 วันที่ผ่านมา

      @@CodeCr4fter you could try to apply them to 2d or even 3d characters

  • @johnnypgames
    @johnnypgames 4 วันที่ผ่านมา

    open source? seems fun to play with

    • @CodeCr4fter
      @CodeCr4fter 4 วันที่ผ่านมา

      I created a repository if you'd still like to play with it :) Link is in the description.

  • @oli111222
    @oli111222 4 วันที่ผ่านมา

    I love your way of presenting, and also that you show not just the success, but also the strugle you had with all the different problems and steps! Thats what programming is mostly about. Also very clean code, readable, necessities documented and well organized. Good work! Like every feedback, there is a "but"... The computation time and the fps... I'd highly recommend, especially when it comes down to visualising, using different python libraries which are already solving for that, such as numba, taichi, etc... There are a lot of different libraries out there optimized for not just matrix, but also tensor optimizations. If you wanna know more, I once made a good "speedcomparison" of all libraries and different implementations, demonstrated on the mandelbrot set (not released yet). Let me know, and I will share the sourcecode with you. Long story short: Keep up the good work :) mandelbrot demo: th-cam.com/video/XV2CVJAfVJk/w-d-xo.html

    • @CodeCr4fter
      @CodeCr4fter 4 วันที่ผ่านมา

      Thank you for the tips! You're visualization looks amazing, I'll make sure to try out the libraries you mentioned!

  • @HoSza1
    @HoSza1 6 วันที่ผ่านมา

    You wrote it in Turtle. 😂

    • @CodeCr4fter
      @CodeCr4fter 6 วันที่ผ่านมา

      That's a good one 😂

  • @kas_tv-fg1xk
    @kas_tv-fg1xk 6 วันที่ผ่านมา

    I've done similar experiments, and I've also tried to do it in python.tell me, have you done any optimizations, or is it just a fairly long rendering?

    • @CodeCr4fter
      @CodeCr4fter 6 วันที่ผ่านมา

      The things that I tried are mentioned in the video, I haven't done anything else yet. Rendering certainly slows the simulation down, it should be done on a separate thread

    • @kas_tv-fg1xk
      @kas_tv-fg1xk 5 วันที่ผ่านมา

      @@CodeCr4fter Yes, like you, I had optimization problems related to the number of pheromones being tested.I've been experimenting with this for a long time, but I can say that dividing space is really a great idea that I saw when I was working on another project.Dividing space into equal parts is a good idea when the objects being checked are the same size, but within the same project I ran into the problem that some objects were larger than others, so much so that if you leave the space as finely divided, then collisions with the object could not be properly processed, and if you increase the area of the cells, it turned out that the optimization suffered much worse

  • @74Gee
    @74Gee 6 วันที่ผ่านมา

    There's another fairly easy metric to implement. That's food levels in the any nest - ant pheromones change from building to scavenging when the food gets low. Also builders could allow more ants to live in the colony. Hope you open source this, I'd love to have a play, I love ants, they're truly fascinating.

    • @CodeCr4fter
      @CodeCr4fter 6 วันที่ผ่านมา

      Thanks for the idea!

    • @CodeCr4fter
      @CodeCr4fter 4 วันที่ผ่านมา

      I created a repository if you'd still like to play with it :) Link is in the description.

    • @74Gee
      @74Gee 4 วันที่ผ่านมา

      @@CodeCr4fter Thanks!! Stared and forked :)

    • @Bee-eautiful
      @Bee-eautiful 3 วันที่ผ่านมา

      ants truly are fascinating indeed

    • @Bee-eautiful
      @Bee-eautiful 3 วันที่ผ่านมา

      @@CodeCr4fterthanks a lot, i'll be sure to check this out later when i have time, this was awesome!

  • @peskarr
    @peskarr 6 วันที่ผ่านมา

    Cool stuff, great story, but cheap MIDI music really hurts sometimes.

    • @CodeCr4fter
      @CodeCr4fter 6 วันที่ผ่านมา

      Thank you! I didn't really spend a long time picking music but if it's that bad I'll definitely try to put more effort into that in the next video

    • @Omena0
      @Omena0 3 วันที่ผ่านมา

      ​@@CodeCr4fterI don't think its bad at all

    • @sirynka
      @sirynka 3 วันที่ผ่านมา

      It's just extremely loud compared to your narration

    • @CodeCr4fter
      @CodeCr4fter 3 วันที่ผ่านมา

      @@sirynka You mean the parts when I'm not talking right?

    • @sirynka
      @sirynka 4 ชั่วโมงที่ผ่านมา

      @@CodeCr4fter yeah

  • @requestfx5585
    @requestfx5585 6 วันที่ผ่านมา

    Choosing the right algorithms and optimizations is always important but I wouldnt use python. If you want to go for speed and in this case simulating hundreds or thousand of ants you probably should go with zig. The only way python could be remotely close is by using numpy I think it was which uses C code behind making it fast. Using zig with sfml for rendering would be a good way and probably a huge improvement, could be also interesting of comparing the speed to python but watch out for the rendering since that can make a difference aswell. I would write the logic code separate from the rendering code so running the simulation without any rendering can be a good way of measuring the performance. Alternatively using c++ will give you similar performance but in my opinion it's easier than zig but memory safety is not enforced 👉👈

    • @CodeCr4fter
      @CodeCr4fter 6 วันที่ผ่านมา

      Thank you for the feedback! You're absolutely right, python is not made for this kind of task. Separating rendering from logic is a very good idea as well, I'll try to implement that. I've never heard of zig but I'll look into that. Thanks again!

    • @requestfx5585
      @requestfx5585 6 วันที่ผ่านมา

      @CodeCr4fter yeah no problem, zig is a relatively new language that "replaces" the c language, which is does pretty good and gains a lot of popularity. It implements safety features like rust and decent memory safety (no garbage collector). Its already a usable language which basically has all features implemented that are needed (v 0.13.0), it's usage is not that complicated but the hard part is that the documentation is weak and very not beginner friendly. Features that are awesome is you can use any c library in zig, c++ as well I heard? But I didn't test that yet, you can cross compile easily to a different system / architecture arm, x32, even compile to webassembly if you like, has testing support directly built into it which I never heard of in any other language.

  • @maximeduchalet4662
    @maximeduchalet4662 6 วันที่ผ่านมา

    very nice, maybe try multiple types of pheromones? i dunno you did something pretty cool

    • @CodeCr4fter
      @CodeCr4fter 6 วันที่ผ่านมา

      Thanks for the idea! I'll see what i can do

  • @dfunited1
    @dfunited1 6 วันที่ผ่านมา

    Thank you so much for a well made and thought provoking video. I've mostly been thinking about the fewest numbers of phermones and fewest number of "rules" over the ants' behavior. One question, how do ants know where the nest is? I'm not sure they have individual awareness, other than "that direction smells like exploration, that direction smells like food, that direction smells like combat". Just food for thought. Again, thanks.

    • @CodeCr4fter
      @CodeCr4fter 6 วันที่ผ่านมา

      Thanks for the comment! I've read they actually do have spatial awareness and can use landmarks for navigation, some even build them (some desert species). They also use a thing called 'path integration' which basically means that they remember turns and count steps to get back to the anthill.

  • @ohimdabiggestbird
    @ohimdabiggestbird 7 วันที่ผ่านมา

    u already know that u gotta throw some ai magic into that, u better

    • @CodeCr4fter
      @CodeCr4fter 6 วันที่ผ่านมา

      I'll try to do that in the next video for sure!

  • @Resursator
    @Resursator 7 วันที่ผ่านมา

    I like how the first bug you met was a pheromone loop of death. It's kinda realistic.

  • @fte6
    @fte6 7 วันที่ผ่านมา

    Good work!

    • @CodeCr4fter
      @CodeCr4fter 7 วันที่ผ่านมา

      Thank you, I appreciate it!

  • @thomasveal7697
    @thomasveal7697 7 วันที่ผ่านมา

    underrated chanel

    • @CodeCr4fter
      @CodeCr4fter 7 วันที่ผ่านมา

      Thank you!

  • @SetTheCurve
    @SetTheCurve 7 วันที่ผ่านมา

    My intuition tells me that your method of optimization isn’t ideal. Optimizing slow code is a bandaid. Switching to a method that isn’t slow, and optimizing that, is a superior path to performance. The code that was partitioned is still slow code.

    • @CodeCr4fter
      @CodeCr4fter 7 วันที่ผ่านมา

      Thanks for the feedback! You're right, I'll try to fix that in the next video

  • @LangSphere
    @LangSphere 7 วันที่ผ่านมา

    0:02 ant colonies when humans aren't looking:

  • @minatimanil
    @minatimanil 7 วันที่ผ่านมา

    This is cool man. Keep it up, I enjoyed the video. Honestly shocked you aren't a bigger channel.

    • @CodeCr4fter
      @CodeCr4fter 7 วันที่ผ่านมา

      I'm glad you liked it!

    • @Bee-eautiful
      @Bee-eautiful 3 วันที่ผ่านมา

      how does such quality content has only 172 subscribers? let me fix that, i'll bring in both of my alts

    • @CodeCr4fter
      @CodeCr4fter 3 วันที่ผ่านมา

      Thank you so much bro!

  • @RS_Chrono610
    @RS_Chrono610 7 วันที่ผ่านมา

    can we get the code great work btw

    • @CodeCr4fter
      @CodeCr4fter 7 วันที่ผ่านมา

      Thank you! I'll consider creating a repository

    • @CodeCr4fter
      @CodeCr4fter 4 วันที่ผ่านมา

      I created a repository if you'd still like to play with it :) Link is in the description.

  • @okolenmi7511
    @okolenmi7511 7 วันที่ผ่านมา

    You can make ants more realistic. They should go back home and stay there some time when they have low energy. Also add more types of pheromones, enemies or fights with other colonies.

    • @CodeCr4fter
      @CodeCr4fter 7 วันที่ผ่านมา

      Thank you for your feedback! I'm actually planning on developing it further and try to use AI

    • @kas_tv-fg1xk
      @kas_tv-fg1xk 5 วันที่ผ่านมา

      regarding realism, I can say that in many similar implementations, ants do not know the way to the anthill, just as they do not know the way to food and remember it through pheromones, this allows ants to move not quite in a straight line to the anthill, but also to avoid potential obstacles

    • @CodeCr4fter
      @CodeCr4fter 5 วันที่ผ่านมา

      I'm gonna try to do that in the next video, implement more types of pheromones and add obstacles on the plane.

  • @okolenmi7511
    @okolenmi7511 7 วันที่ผ่านมา

    You need a better mic. It's the only bad thing in the video.

    • @axospyeyes281
      @axospyeyes281 7 วันที่ผ่านมา

      eh, it's fine

    • @CodeCr4fter
      @CodeCr4fter 7 วันที่ผ่านมา

      Thanks! I know, I was trying to improve it during editing but I could only do so much

  • @mushrafaltaf
    @mushrafaltaf 7 วันที่ผ่านมา

    I enjoyed this! Keep it up!

    • @CodeCr4fter
      @CodeCr4fter 7 วันที่ผ่านมา

      Thank you!

  • @Kaviranghari
    @Kaviranghari 7 วันที่ผ่านมา

    7:40 i can bro I can and i do Its like a ton is lifted off your forehead and chest and you can breathe normally and your brain chills out

  • @Kaviranghari
    @Kaviranghari 7 วันที่ผ่านมา

    I literally thought i was watching some successful channel For 10 minutes Then i saw the view count and then the sub count and i was blown away

    • @CodeCr4fter
      @CodeCr4fter 7 วันที่ผ่านมา

      Thanks bro, it means a lot!

  • @amosky5105
    @amosky5105 8 วันที่ผ่านมา

    Nice work and editing !

    • @CodeCr4fter
      @CodeCr4fter 8 วันที่ผ่านมา

      Thanks a lot!

  • @fantasticalthoughts
    @fantasticalthoughts 8 วันที่ผ่านมา

    good vid

    • @CodeCr4fter
      @CodeCr4fter 8 วันที่ผ่านมา

      Thank you!

  • @unknown1689-e9e
    @unknown1689-e9e 8 วันที่ผ่านมา

    Nice work bro!

    • @CodeCr4fter
      @CodeCr4fter 8 วันที่ผ่านมา

      Thanks a lot!

  • @yosef_ii
    @yosef_ii 8 วันที่ผ่านมา

    Amazing work!

    • @CodeCr4fter
      @CodeCr4fter 8 วันที่ผ่านมา

      I'm glad you liked it ❤️

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

    Preventing kids from saying "first"

  • @schaku-l2m
    @schaku-l2m หลายเดือนก่อน

    can you please make a tutorial for absolute beginners like myself i dont know how to code at all

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

      Hi! I'm sorry but I don't plan to do any tutorials for absolute beginners at least for now. If you want to learn how to code I'd recommend freecodecamp videos on youtube.

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

    What?

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

    Yo 👋 you got the source code? I'm following along and I'm wondering if I missed a line or 2 cause it draws the circle & ball but they don't move. I got as far as 2:05 before trying to debug it myself (and with gemini) but I can't find the issue. If I can get it to work, this is an amazing tutorial tho!

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

      Hi! I'm glad you enjoyed! I don't plan to release the source code but I will check it tomorrow and see if everything is on the video. If the balls aren't moving the reason is either the velocity is not being updated every frame or the screen is not being updated (probably the first one)

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

      @@CodeCr4fter So I got that part working now but the last thing to get working is the program for multiple balls. I can't really test the collision script without having multiple balls to collide. Thanks Again!

  • @Proder-ss8qw
    @Proder-ss8qw หลายเดือนก่อน

    I was shocked when i saw you have only 30 subscribers, this is really amazing content, you earned subscriber🎉 Suggestions Voice is very low Show code frame occupying full frame

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

      Thanks a lot! I will definitely fix that in the next video

  • @UmarAdamu-ec5kr
    @UmarAdamu-ec5kr หลายเดือนก่อน

    Can you please make a Pydroid3 pygame code for this simulation for Mobile 🙏🙏

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

      Sorry but that's outside of my field of interest

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

    GitHub?

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

      Maybe in the future

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

    I have always been fascinated with Conway’s game of life. How did you deal with what happens when a cell is on the edge?

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

      They behave the same way other cells do. It's a finite grid so edge cells can only have 5 neighbors and the corner ones - 3.

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

      @@CodeCr4fter i see keep ip the great work!

  • @سامرعمادالدين
    @سامرعمادالدين หลายเดือนก่อน

    Nice video but you need to bost the volume 😉

    • @UmarAdamu-ec5kr
      @UmarAdamu-ec5kr หลายเดือนก่อน

      Can you please make a code for Pydroid3 pygame on mobile of this simulation.