Skip to main content

分形绘图库,支持Julia集、Mandelbrot集、IFS、L-System等

Project description

Draw Fractal Image By Python

A Python fractal drawing library supporting Julia Set, Mandelbrot Set, IFS, L-System and more.

Install

pip install fractal

Or download the package:

pip install -e .

Dependencies:

  • Pillow >= 8.0.0
  • numpy >= 1.20.0

Features

  • Julia Set - Interactive zoom with mouse
  • Mandelbrot Set - Classic Mandelbrot fractal
  • IFS - Iterated Function System (fern, leaf, tree, etc.)
  • L-System - Lindenmayer System (Koch curve, dragon, tree, etc.)
  • CIFS - Complex Iterated Function System

GUI Operations

  • Save: Click "Save" button or Ctrl+P
  • Save As: Click "Save As..." to choose format (PNG/JPG/BMP)
  • Zoom In: Left click to show selection box, drag to move, click again to confirm
  • Zoom Out: Right click
  • Cancel Selection: Press ESC or right click

Examples

L-System

from fractal import Pen
from math import sqrt
p = Pen([350, 270])
p.setPoint([140, 60])
p.setWidth(1)
p.doD0L(omega="L", P={"L": "L+R", "R": "L-R"},
              delta=90, times=15, length=200, rate=sqrt(2))
p.wait()

from fractal import Pen

p = Pen([500, 500], title="Window")
p.setPoint([495, 495])
p.setAngle(90)
p.doD0L(omega="f+f+f+f", P={"f": "ff+f--f+f"},
        delta=90, times=5, length=490, rate=3)
p.wait()

from fractal import Pen
p = Pen([420,420])
p.setPoint([10,10])
p.doD0L(omega = "L", P = {"L": "LFRFL-FF-RFLFR+FF+LFRFL", "R": "RFLFR+FF+LFRFL-FF-RFLFR"}, delta =  90, times = 4, length = 200 , rate = 3)
p.wait()

from fractal import Pen
p = Pen([400, 470])
p.setAngle(90)
p.setPoint([200,470])
p.doD0L(omega = "f", P = {"f": "h[-f][+f]hf", "h": "hh"}, delta = 25.7, times = 7, length = 400, rate = 2.17)
p.wait()

from fractal import Pen
p = Pen([400, 470])
p.setAngle(90)
p.setPoint([170, 470])
p.doD0L(omega="f", P={"f": "h+[[f]-f]-h[-hf]+f", "h": "hh"},
        delta=22.5, times=6, length=400, rate=2.3)
p.wait()

IFS

from fractal import IFS
from random import random

def ifsp(x, y):
    p = random()
    if p < 0.01:
        return (0, 0.16 * y)
    elif p < 0.07:
        if random() > 0.5:
            return (0.21 * x - 0.25 * y, 0.25 * x + 0.21 * y + 0.44)
        else:
            return (-0.2 * x + 0.26 * y, 0.23 * x + 0.22 * y + 0.6)
    else:
        return (0.85 * x + 0.1 * y, -0.05 * x + 0.85 * y + 0.6)

ob = IFS([400, 500], title = "Leaf")
ob.setPx(100, 100, 100)
ob.setIfsp(ifsp)
ob.doIFS(200000)
ob.wait()

# Box IFS
from fractal import IFS
from random import randint


def ifsp(x, y):
    p = randint(1, 5)
    if p == 1:
        return (x / 3, y / 3)
    elif p == 2:
        return (x / 3 + 2 / 3, y / 3)
    elif p == 3:
        return (x / 3 + 1 / 3, y / 3 + 1 / 3)
    elif p == 4:
        return (x / 3, y / 3 + 2 / 3)
    else:
        return (x / 3 + 2 / 3, y / 3 + 2 / 3)

ob = IFS([500, 500], title="Box")
ob.setPx(490, 5, 5)
ob.setIfsp(ifsp)
ob.doIFS(200000)
ob.wait()

from fractal import IFS

ifscode = [
    [0.879, 0.054, -0.051, 0.878, 0.077, 0.123, 0.123],
    [0.1, -0.193, 0.285, 0.224, 0.174, 0.169, 0.169],
    [0.008, 0.135, 0, 0.204, 0.075, 0.074, 0.074],
    [0.402, 0.045, 0.016, -0.197, 0.111, 0.193, 0.193]
]

ifs = IFS([500, 500])
ifs.setPx(700, 0, 0)
ifs.setIfsCode(ifscode)
ifs.doIFS(200000)
ifs.wait()

from fractal import IFS

code = [
    [0.195, -0.488, 0.344, 0.443, 0.4431, 0.2452, 0.2],
    [0.462, 0.414, -0.252, 0.361, 0.2511, 0.5692, 0.2],
    [-0.637, 0, 0, 0.501, 0.8562, 0.2512, 0.2],
    [-0.035, 0.07, -0.469, 0.022, 0.4884, 0.5069, 0.2],
    [-0.058, -0.07, -0.453, -0.111, 0.5976, 0.0969, 0.2]
]

ifs = IFS([500,500])
ifs.setCoordinate()
ifs.setPx(500, 0, 0)
ifs.setIfsCode(code)
ifs.doIFS(200000)
ifs.wait()

Julia

from fractal import Julia
ju = Julia([500, 500])
ju.setC(0 - 1j)
ju.doJulia(500)
ju.wait()

-1.25 + 0j

-0.605-0.45j

Mandelbrot

from fractal import Mandelbrot
man = Mandelbrot([500, 500])
man.setRange(5, 5)
man.doMandelbrot(200)
man.wait()

License

MIT License

Author

L.Chen (pysrc)

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

fractal-0.5.0.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

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

fractal-0.5.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file fractal-0.5.0.tar.gz.

File metadata

  • Download URL: fractal-0.5.0.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for fractal-0.5.0.tar.gz
Algorithm Hash digest
SHA256 3cd30ece9b4ef8e6b8375db99d7ae798718fd13f5a90a29397552dbfdc10ccb6
MD5 d9b69176ac2e4d7f934457ae7442fd2a
BLAKE2b-256 669021992a7e8169e876f952d6e2f9f7ccaa29012c221163464bff05fc8c9026

See more details on using hashes here.

File details

Details for the file fractal-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: fractal-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for fractal-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3211b72a9efb969e2cff6922d74f1a0f342819d0b591c828b09e74818f7e8f17
MD5 6ddd5c74ad716eeb7aa3b036fa00b548
BLAKE2b-256 fc0286b385565418b901a6635889e87d1ebff972241636167904c8fd4ba49b82

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