Code Monkey home page Code Monkey logo

chaotic-system's Introduction

chaos-balls

A Simulation of balls bouncing around in a circular ring, inspired by a Numberphile video on chaotic systems. The simulation demonstates how chaos and complexity arises from something as simple as balls bouncing in a ring. Written in python3 and pygame.

Requirements

Install these packages using pip:

  • pygame. preferably version 2.0.1
pip install pygame -V 2.0.1

Run

Simply run the chaos_balls.py file either by double clicking it or running the following command in the terminal

py chaos_balls.py

Features

To Add/Remove balls and manipulate their properties, i.e velocity, position, etc you can do so by opening chaos_balls.py in a text editor and follow the instructions around line 150. Will make this more user friendly in the future but for now just mess around with the source code.

Example

First we will create the object:

redball_test = Balls() Now the arguments that go in the class Balls are seen in the template below:

template = Balls("name", color, radius, thickness, x-coordinate, y-coordinate, [collision sound file] optional)

  • name: name of the ball, call it whatever you like -> str
  • color: color of the ball. color is a tuple of the format (r,g,b)
  • radius: radius of the ball -> float or int
  • thickness: set to 0 if you want a solid ball. If set to a non-zero value, then ball will be drawn as a ring and the thickness controls how thick the outline is. -> float or int
  • x & y coordinates: The position of the center of the ball. Note the top left corner of the window is the origin (0,0) and y increases (positive) going down
  • collision sound file: the audio file that's played during collisions with the walls of the ring. Feel free to use your own audio files, make sure to sure to convert them to .wav and add them to the audio folder.

To add a red ball at the position 200, 300.

redball_test = Balls("test", (255, 0, 0), 8, 0, 200, 300)

Note: color is red which is (255,0,0) in rgb. x coordinate is set to width//2 which is midway and y coordinate is set to height//2 +10 which is midway and 10 pixels down.

Controls

  • Spacebar to pause

That's about it!

chaotic-system's People

Contributors

anasald avatar quantumzain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

chaotic-system's Issues

Circle is vanishing?

i wanted to insert a circle. but whenever i insert it, it disappears immediately. i don't think it's a problem with the code. i probably just don't understand it properly. could you help me?

Readme incorrectly says P key pauses the sim instead of the spacebar

the title sums it up, this issue is more of a trying to get an idea on how git hub issues work rather than actually writing about a big, am just writing words here for the sake of words. This is the second sentence. After further inspection I've made an interesting observation whereby pressing the spacebar would pause the simulation. Maybe consider updating the README and make sure the pause button is clearly stated within the program. Also, if paused, why not make us drag the balls aroumd?

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.