Giter VIP home page Giter VIP logo

pynboids's Introduction

PyNBoids

Preview

A Python Boids Simulation

This is a Boids simulation, written in Python3, with Pygame2 and NumPy.

To use: Save the pynboids_sp.py file (and nboids.png if you want the icon, not required) and run via python. (Example: python3 pynboids.py)

Esc key to quit.

I've included several customizable settings near the top of the code.
You can adjust window size, fullscreen, fps, and how many boids to spawn, as well as whether they avoid the screen edges or wrap to the other side, change the background color, or turn the boids into fish! ;)

Update (11/14/22):

Minor updates to several files. New nboids_ss.py version is a linux-only pseudo-screensaver that requires xprintidle be installed. BUT, due to a possible memory leak, the screensaver must be started using run_ss.py.

Update (5/20/21):

New pynboids_sp.py version, implements a spatial partitioning grid to improve efficiency of detecting other boids. Most efficient version so far!

Update (5/16/21):

Added pynboids2.py version, an update to the original pynboids, with numpy array methods from pixelboids.py to improve efficiency. 2x more boids then b4.

Update (5/14/21):

Added pixelboids.py version, draws boids as pixels in surfarray that fades as they move. Distance sorting & for-loop math replaced with numpy array math. Uses a fading surfArray to create tails, pixelation makes them look animated.

Special Thanks: (Let me know if I forgot anyone.)

I couldn't have gotten this far without the Pygame Discord channel:
CozyFractal, for help with the spatial partition grid & improving efficiency.
Mega_JC, Ghast, and bydariogamer, for answering various questions I had.

For more information, and future updates, see github page.


    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.
    If not, see: https://www.gnu.org/licenses/gpl-3.0.html
Copyright (c) 2021 Nikolaus Stromberg - [email protected]

pynboids's People

Contributors

nikorasu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pynboids's Issues

How would I make them follow the mouse?

Hi :)

I would love to borrow your code to use in my program that I write for learning purposes only. There, stuff is following the mouse cursor on screen.
You implementation of boids looks very nice and seems also very performant. Now, your code isn't the easiest to read. Much math. Very complex. Variables have names like: "tAvejAng". What's that? Time-average-junction-angle? xD
Edit: Well I know have "targetAverage_j_Angle" and that basically represents my understanding of your code.

I like the new stuff I learn from your code: self.boidSize = 22 if isFish else 17 and if (neighborCount := len(neighborBoids)) > 1: I didn't know about that.. :)

I generally know how to get and use the mousecursor postion and speed. The only issue is that it seems like the movement is all random, that there is no destination I could hijack. The destination is some ephemeral "where the most boids are", I guess. Maybe... it's so hard to read xD

Can you give me a hint where to start?

I hope you'll see this in due time. But if not, thenn I have to figure it out. Maybe I start by changing variable names.
Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.