Code Monkey home page Code Monkey logo

chaosgamepython's Introduction

Chaos Game implementation in Python

Chaos Game

Description

This is a simple framework implementation of the Chaos Game in Python. The Chaos Game is a mathematical game that simulates the process of a trajectory of a point subject to non-linear iterative function systems. The game is played by plotting a point at a random position in a square and then iteratively moving the point halfway towards one of the vertices of a polygon, randomly chosen from a given set of vertices. The vertices are fixed for a given polygon, and do not change position. The polygon used in this implementation is a triangle, but it can be easily changed to any other polygon.

The Chaos Game is a form of dynamical system. The game can be extended to higher dimensions by using a regular polyhedron or even a higher-dimensional polytope as the space to move in, and a set of non-linear functions. The game can also be played with a circle instead of a polygon.

This library only supports PyGame for visualization, but it can be easily extended to other frameworks.

Usage

With inheriting ChaosGameGraphic abstract class, you can create new shapes. The only thing you need to do is to implement the abstract methods. You can also change the number of iterations and the size of the window in the main.py file. ChaosGameGraphic class follows the Iterator design pattern. It is used to iterate over the vertices of the polygon. The iterator is implemented in the Polygon class.

With inheriting GraphicDrawer abstract class, you can create new graphic drawers. The only thing you need to do is to implement the abstract methods. You can also change the number of iterations and the size of the window in the main.py file.

PygameGraphicDrawer is a concrete implementation of GraphicDrawer abstract class. It uses PyGame to draw the points on the screen.

Built-in shapes

Sierpinski triangle

Sierpinski triangle is a fractal and attractive fixed set with the overall shape of an equilateral triangle, subdivided recursively into smaller equilateral triangles. Originally constructed as a curve, this is one of the basic examples of self-similar sets, i.e., it is a mathematically generated pattern that can be reproducible at any magnification or reduction. It is named after the Polish mathematician Wacław Sierpiński, but appeared as a decorative pattern many centuries prior to the work of Sierpiński.

Sierpinski triangle

Barnsley fern

The Barnsley fern is a fractal named after the British mathematician Michael Barnsley who first described it in his book Fractals Everywhere. He made it to resemble the black spleenwort, Asplenium adiantum-nigrum. The "stem" of the fern is created by the graph of the equation

Barnsley fern

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.