Skip to content
crypt0lithPublic

About

Create moiré patterns in Python

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

moiré

Generate moiré patterns from simple array ops.

All of the pattern generation logic is located in a single function, moire_pattern().

Usage

Parameters

  • n int: Size of the image width and height in pixels (n x n).
  • k float: Scaling factor affecting pattern frequency and density.
  • kernel {'elliptical', 'hexagonal', 'radial', 'spiral', 'square', 'star', 'wave'} | Callable[[ndarray, ndarray], ndarray]: Determines pattern shape. Can be the name of a preset kernel or a callable object which accepts two arrays and returns an array.
  • colorize bool: False for greyscale (default), True for RGB.

Preset Kernels

The global KERNELS dict provides a namespace for preset kernel functions.

  • 'elliptical'
  • 'hexagonal'
  • 'radial'
  • 'spiral'
  • 'square'
  • 'star'
  • 'wave'

The presets offer quite a bit when it comes to experimentation.

This is especially true if one were to chain them together using higher-order lambdas, such as in the following code:

from moire import moire_pattern, KERNELS
from PIL import Image

# using the product of two other patterns as the pattern
kernel_chain = lambda x, y: KERNELS['hexagonal'](x, y) * KERNELS['star'](x, y)

output = moire_pattern(m=999, k=777, kernel=kernel_chain, colorize=True)

Image.fromarray(output).show()

... which creates this output image:

moire_rainbow

Example Usage

Using the 'spiral' preset kernel:

from moire import moire_pattern
from PIL import Image

output = moire_pattern(n=500, k=100.0, kernel='spiral')

Image.fromarray(output).show()

Using a custom kernel, with colorized output:

import numpy as np
from moire import moire_pattern
from PIL import Image

def custom_kernel(x, y):
    return np.sin(x) * np.cos(y)

output = moire_pattern(n=500, k=100.0, kernel=custom_kernel, colorize=True)

Image.fromarray(output).show()

Additional Resources

About

Create moiré patterns in Python

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages