Skip to main content

This package implements common fractals in pgzero and pygame. Fractal generation code written in C for fast rendering.

Project description

common-fractals

This package includes classes for drawing common fractals in pgzero and pygame.


Usage

This package has 5 fractals implemented:

  • Koch Snowflake (KochSnowflake)
  • Koch Anti-Snowflake (KochAntiSnowflake)
  • Mandelbrot Set (MandelbrotSet)
  • Newton Fractal (NewtonFractal)
  • Sierpinski Triangle (SierpinskiTriangle)
  • Julia Sets (JuliaSet)

This package also includes a base Fractal class which is the super class for all of the fractals mentioned above. The Fractal class does not change the effects or add methods to the sub classes.

Koch Snowflake

An example of drawing the Koch Snowflake in a pgzero and pygame game is shown below (this example includes all of the parameters available in the KochSnowflake class):

from common_fractals import KochSnowflake # Imports KochSnowflake necessary for creating the Snowflake

koch_snowflake = KochSnowflake(iterations = 20, side_length = 200, topleft = (100, 100)) # Creates the Snowflake. You should not call this in your draw function because that would decrease speed significantly

... # Your code here

    koch_snowflake.draw_pgzero(screen, color = "green") # Draws the Snowflake. The screen parameter should be the screen you use to draw on the window

All of them have the same parameters. For pygame, the screen parameter is the surface of which you want to draw the Snowflake onto.

Koch Anti-Snowflake

An example of drawing the Koch Anti-Snowflake in a pgzero and pygame game is shown below (this example includes all of the parameters available in the KochAntiSnowflake class):

from common_fractals import KochAntiSnowflake # Imports KochAntiSnowflake necessary for creating the Anti-Snowflake

koch_anti_snowflake = KochAntiSnowflake(iterations = 20, side_length = 200, topleft = (100, 100)) # Creates the Anti-Snowflake. You should not call this in your while loop because that would decrease speed significantly

... # Your code here

    koch_anti_snowflake.draw_pygame(display_screen, color = "green") # Draws the Snowflake. For pygame, the surface parameter should be the display_screen or a different Surface. For pgzero, the screen parameter should be the screen you use to draw on the window

koch_anti_snowflake has the same methods as the KochSnowflake.

Mandelbrot Set

An example of drawing the Mandelbrot Set in a pgzero and pygame game is shown in the two examples below (this example includes all of the parameters available in the MandelbrotSet class):

from common_fractals import MandelbrotSet # Imports MandelbrotSet necessary for creating the Mandelbrot Set

mandelbrot_set = MandelbrotSet(iterations = 1000, scale = 50, width = 600, height = 600, topleft = (100, 100)) # Creates the Mandelbrot Set. You should not call this in your while loop because that would decrease speed significantly

... # Your code here

    mandelbrot_set.draw_pgzero(screen, color = "green") # Draws the Mandelbrot Set. For pygame, the surface parameter should be the display_screen or a different Surface. For pgzero, the screen parameter should be the screen you use to draw on the window

mandelbrot_set has the same methods as the KochSnowflake and KochAntiSnowflake.

Newton Fractal

An example of drawing the Newton Fractal in a pgzero and pygame game is shown in the two examples below (this example includes all of the parameters available in the NewtonFractal class):

from common_fractals import NewtonFractal # Imports NewtonFractal necessary for creating the Newton Fractal

newton_fractal = NewtonFractal(iterations = 50, width = 600, height = 600, scale = 75, animate = True, show_roots = True, point_scale = 1 / 2,
                 root_scale: float = 1, func = lambda x: x ** 3 + 2 * (x ** 2) + 10, colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)], print_current_iter = True) # Creates the Newton Fractal. You should not call this in your draw function because that would decrease speed significantly. The length of the colors must be equal to or greater than the degree measure (the highest power in func. In this case, it is 3)

... # Your code here

    newton_fractal.draw_pygame(display_screen, color = "green") # Draws the Newton Fractal. For pygame, the surface parameter should be the display_screen or a different Surface. For pgzero, the screen parameter should be the screen you use to draw on the window

newton_fractal has the same methods as the KochSnowflake, KochAntiSnowflake, and MandelbrotSet.


Versions

Version 0.0.1: Base Code added. (Latest) Version 0.0.2: Julia Sets added

Coming Soon

Version 0.0.3: C Code for the Julia Sets added. Version 0.0.4: C code for Koch Snowflake (KochSnowflake) added.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

common_fractals-0.0.2.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

common_fractals-0.0.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file common_fractals-0.0.2.tar.gz.

File metadata

  • Download URL: common_fractals-0.0.2.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for common_fractals-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f4039afaa4a268fd4893a3eedb0cd5b22c154586fe90f50208f7250051bf4984
MD5 4c490a7d514e83e31bffe0d2ab6ff23d
BLAKE2b-256 f88ae5c5ac16ebfe6a8318800f24174e6852a50d38d5413fd5a200ba32a7405f

See more details on using hashes here.

File details

Details for the file common_fractals-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for common_fractals-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f9e2dabb785ecc5b9dd9325803e4d99ea2a5f4db624ac581ea7ae2746e4ba21d
MD5 95b2122bc3ba56fb492ab824a6f9ec75
BLAKE2b-256 644325e90673c311359d16b8a3db9246996c29688f6327ffabe1e965325dc3bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page