zooui.tilesystem.tileproviders.ferndynamictileprovider module

Dynamic tile provider for Barnsley’s fern.

class zooui.tilesystem.tileproviders.ferndynamictileprovider.FernTileProvider(tilecache)[source]

Bases: DynamicTileProvider

Constructor :

FernTileProvider(tilecache)

Parameters :

tilecache : TileCache

FernTileProvider(tilecache) –> FernTileProvider

FernTileProvider objects are used for generating tiles of Barnsley’s fern iterated function system.

This dynamic tile provider generates fractal images of Barnsley’s fern using an iterated function system (IFS). The fern is created by randomly applying one of four affine transformations to points, with each transformation having a specific probability of being chosen.

Implementation Notes:
  • Inherits from DynamicTileProvider

  • Uses four affine transformations with different probabilities:
    • rachis (stem): 1% probability

    • left hand first pinna: 7% probability

    • right hand first pinna: 7% probability

    • body of fern: 85% probability

  • Generates up to max_iterations (50000) points

  • Stops after max_points (10000) points are drawn on tile

  • Tiles are 256x256 pixels saved as PNG

  • Color is RGB (100, 170, 0) for a green fern appearance

Constructor :

FernTileProvider(tilecache)

Parameters :

tilecache : Any

FernTileProvider(tilecache) –> None

Create a new FernTileProvider with the given TileCache.

The tilecache parameter is the TileCache instance that this provider will use to store generated fern fractal tiles.

filext = 'png'
tilesize = 256
aspect_ratio = 1.0
max_iterations = 50000
max_points = 10000
transformations = [(0.01, (0.0, 0.0, 0.0, 0.0, 0.16, 0.0)), (0.07, (0.2, -0.26, 0.0, 0.23, 0.22, 1.6)), (0.07, (-0.15, 0.28, 0.0, 0.26, 0.24, 0.44)), (0.85, (0.85, 0.04, 0.0, -0.04, 0.85, 1.6))]
color = (100, 170, 0)
__choose_transformation()
Method :

FernTileProvider.__choose_transformation()

Parameters :

None

FernTileProvider.__choose_transformation() –> Tuple[float, float, float, float, float, float]

Randomly choose a transformation based on the probability of each transformation being chosen.

This method implements probabilistic selection from the four fern transformations. A random value between 0 and 1 is generated, and transformations are tested in order until one is selected based on cumulative probability.

Implementation Notes:
  • Generates random float in range [0, 1)

  • Iterates through transformations in order

  • Subtracts each probability from random value

  • Returns transformation when random value <= probability

  • Returns 6-tuple: (a, b, c, d, e, f) for affine transform

__transform(x, y)
Method :

FernTileProvider.__transform(x, y)

Parameters :

x : float y : float

FernTileProvider.__transform(x, y) –> Tuple[float, float]

Randomly choose a transformation and apply it to x and y, returning the result as a tuple.

This method applies one iteration of the fern’s iterated function system. It selects a transformation using __choose_transformation() and applies the affine transformation to the input coordinates.

Implementation Notes:
  • Calls __choose_transformation() to get transformation coefficients

  • Applies affine transformation: x’ = a*x + b*y + c

  • Applies affine transformation: y’ = d*x + e*y + f

  • Returns new coordinates as tuple (x’, y’)

__draw_point(tile, x, y, tilesize_units)
Method :

FernTileProvider.__draw_point(tile, x, y, tilesize_units)

Parameters :

tile : Image x : float y : float tilesize_units : float

FernTileProvider.__draw_point(tile, x, y, tilesize_units) –> None

Draw the given point on the given tile.

Converts fern coordinate space to pixel coordinates and draws a single pixel on the tile. The y-coordinate is inverted to match image coordinate system (origin at top-left).

Preconditions:
  • 0.0 <= x <= tilesize_units

  • 0.0 <= y <= tilesize_units

Implementation Notes:
  • Scales x from [0, tilesize_units] to [0, tilesize]

  • Clamps x to valid pixel range [0, tilesize-1]

  • Scales y from [0, tilesize_units] to [0, tilesize]

  • Inverts y-coordinate: pixel_y = tilesize - scaled_y

  • Clamps y to valid pixel range [0, tilesize-1]

  • Sets pixel color using self.color (green)

_load_dynamic(tile_id, outfile)[source]
Method :

FernTileProvider._load_dynamic(tile_id, outfile)

Parameters :

tile_id : Tuple[str, int, int, int] outfile : str

FernTileProvider._load_dynamic(tile_id, outfile) –> None

Generate a tile of Barnsley’s fern and save it to outfile.

This method generates a fractal fern image for the specified tile by iterating the fern’s IFS transformations. The tile coordinates (row, col) and tilelevel determine which portion of the fern to render. Points are generated starting from (0, 0) and transformed repeatedly, with points falling within the tile’s boundaries being drawn.

Implementation Notes:
  • Returns early if row/col are out of range for the tilelevel

  • Calculates tile boundaries in fern coordinate space (-5 to 5 for x, 0 to 10 for y)

  • Creates a black RGB image of size tilesize x tilesize

  • Iterates up to max_iterations times, starting from origin (0, 0)

  • Only draws points that fall within the tile boundaries

  • Stops after max_points are drawn to the tile

  • Saves the resulting tile as PNG to outfile