This is a Boids Simulation, written in Python with Pygame.

Overview

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 (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]
You might also like...
Simple plotting for Python. Python wrapper for D3xter - render charts in the browser with simple Python syntax.
Simple plotting for Python. Python wrapper for D3xter - render charts in the browser with simple Python syntax.

PyDexter Simple plotting for Python. Python wrapper for D3xter - render charts in the browser with simple Python syntax. Setup $ pip install PyDexter

Visual Python is a GUI-based Python code generator, developed on the Jupyter Notebook environment as an extension.
Visual Python is a GUI-based Python code generator, developed on the Jupyter Notebook environment as an extension.

Visual Python is a GUI-based Python code generator, developed on the Jupyter Notebook environment as an extension.

A Python Binder that merge 2 files with any extension by creating a new python file and compiling it to exe which runs both payloads.
A Python Binder that merge 2 files with any extension by creating a new python file and compiling it to exe which runs both payloads.

Update ! ANONFILE MIGHT NOT WORK ! About A Python Binder that merge 2 files with any extension by creating a new python file and compiling it to exe w

Declarative statistical visualization library for Python
Declarative statistical visualization library for Python

Altair http://altair-viz.github.io Altair is a declarative statistical visualization library for Python. With Altair, you can spend more time understa

Interactive Data Visualization in the browser, from  Python
Interactive Data Visualization in the browser, from Python

Bokeh is an interactive visualization library for modern web browsers. It provides elegant, concise construction of versatile graphics, and affords hi

Cartopy - a cartographic python library with matplotlib support
Cartopy - a cartographic python library with matplotlib support

Cartopy is a Python package designed to make drawing maps for data analysis and visualisation easy. Table of contents Overview Get in touch License an

A grammar of graphics for Python
A grammar of graphics for Python

plotnine Latest Release License DOI Build Status Coverage Documentation plotnine is an implementation of a grammar of graphics in Python, it is based

a plottling library for python, based on D3

Hello August 2013 Hello! Maybe you're looking for a nice Python interface to build interactive, javascript based plots that look as nice as all those

UNMAINTAINED! Renders beautiful SVG maps in Python.

Kartograph is not maintained anymore As you probably already guessed from the commit history in this repo, Kartograph.py is not maintained, which mean

Comments
  • How would I make them follow the mouse?

    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

    opened by LtqxWYEG 5
Releases(r2)
  • r2(Apr 19, 2021)

    Improved Boid class to be much more importable. Several values need to be passed to class, a few are optional. The example_scene.py file demos importing Boids as Fish, spawning separate groups in tinted layers for fake depth effect. This release was re-published, to put my delta-time implementation back to the correct method, and to update example.

    Source code(tar.gz)
    Source code(zip)
  • r1(Apr 4, 2021)

    Code works pretty good now. Marking a release to save current state. This first release is basically like a rough screensaver, at least when in fullscreen mode. Just a simulation to watch. Although Boids should be able to be imported and used in other projects, not all boid-settings are passable to the class/functions yet, like color or speed. I'll add more in a future update.

    Source code(tar.gz)
    Source code(zip)
Python library that makes it easy for data scientists to create charts.

Chartify Chartify is a Python library that makes it easy for data scientists to create charts. Why use Chartify? Consistent input data format: Spend l

Spotify 3.2k Jan 04, 2023
🧇 Make Waffle Charts in Python.

PyWaffle PyWaffle is an open source, MIT-licensed Python package for plotting waffle charts. It provides a Figure constructor class Waffle, which coul

Guangyang Li 528 Jan 02, 2023
A Bokeh project developed for learning and teaching Bokeh interactive plotting!

Bokeh-Python-Visualization A Bokeh project developed for learning and teaching Bokeh interactive plotting! See my medium blog posts about making bokeh

Will Koehrsen 350 Dec 05, 2022
Make sankey, alluvial and sankey bump plots in ggplot

The goal of ggsankey is to make beautiful sankey, alluvial and sankey bump plots in ggplot2

David Sjoberg 156 Jan 03, 2023
Visualize and compare datasets, target values and associations, with one line of code.

In-depth EDA (target analysis, comparison, feature analysis, correlation) in two lines of code! Sweetviz is an open-source Python library that generat

Francois Bertrand 2.3k Jan 05, 2023
Make visual music sheets for thatskygame (graphical representations of the Sky keyboard)

sky-python-music-sheet-maker This program lets you make visual music sheets for Sky: Children of the Light. It will ask you a few questions, and does

21 Aug 26, 2022
Attractors is a package for simulation and visualization of strange attractors.

attractors Attractors is a package for simulation and visualization of strange attractors. Installation The simplest way to install the module is via

Vignesh M 45 Jul 31, 2022
This project is created to visualize the system statistics such as memory usage, CPU usage, memory accessible by process and much more using Kibana Dashboard with Elasticsearch.

System Stats Visualizer This project is created to visualize the system statistics such as memory usage, CPU usage, memory accessible by process and m

Vishal Teotia 5 Feb 06, 2022
GitHub English Top Charts

Help you discover excellent English projects and get rid of the interference of other spoken language.

kon9chunkit 529 Jan 02, 2023
A D3.js plugin that produces flame graphs from hierarchical data.

d3-flame-graph A D3.js plugin that produces flame graphs from hierarchical data. If you don't know what flame graphs are, check Brendan Gregg's post.

Martin Spier 740 Dec 29, 2022
Automatically generate GitHub activity!

Commit Bot Automatically generate GitHub activity! We've all wanted to be the developer that commits every day, but that requires a lot of work. Let's

Ricky 4 Jun 07, 2022
Statistics and Visualization of acceptance rate, main keyword of CVPR 2021 accepted papers for the main Computer Vision conference (CVPR)

Statistics and Visualization of acceptance rate, main keyword of CVPR 2021 accepted papers for the main Computer Vision conference (CVPR)

Hoseong Lee 78 Aug 23, 2022
Process dataframe in a easily way.

Popanda Written by Shengxuan Wang at OSU. Used for processing dataframe, especially for machine learning. The name is from "Po" in the movie Kung Fu P

ShawnWang 1 Dec 24, 2021
The visual framework is designed on the idea of module and implemented by mixin method

Visual Framework The visual framework is designed on the idea of module and implemented by mixin method. Its biggest feature is the mixins module whic

LEFTeyes 9 Sep 19, 2022
Simple implementation of Self Organizing Maps (SOMs) with rectangular and hexagonal grid topologies

py-self-organizing-map Simple implementation of Self Organizing Maps (SOMs) with rectangular and hexagonal grid topologies. A SOM is a simple unsuperv

Jonas Grebe 1 Feb 10, 2022
Customizing Visual Styles in Plotly

Customizing Visual Styles in Plotly Code for a workshop originally developed for an Unconference session during the Outlier Conference hosted by Data

Data Design Dimension 9 Aug 03, 2022
These data visualizations were created for my introductory computer science course using Python

Homework 2: Matplotlib and Data Visualization Overview These data visualizations were created for my introductory computer science course using Python

Sophia Huang 12 Oct 20, 2022
Interactive plotting for Pandas using Vega-Lite

pdvega: Vega-Lite plotting for Pandas Dataframes pdvega is a library that allows you to quickly create interactive Vega-Lite plots from Pandas datafra

Altair 342 Oct 26, 2022
Mapomatic - Automatic mapping of compiled circuits to low-noise sub-graphs

mapomatic Automatic mapping of compiled circuits to low-noise sub-graphs Overvie

Qiskit Partners 27 Nov 06, 2022
Data Visualizer for Super Mario Kart (SNES)

Data Visualizer for Super Mario Kart (SNES)

MrL314 21 Nov 20, 2022