Skip to content

OliverACollins/PyGrid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyGrid

PyGrid banner

A flexible Python package enabling users to draw several different grid illusions.

Rationale

The purpose of creating this Python package was to provide an easy-to-use tool for developing simple, customisable grid illusions. This is the first package that I am aware of to feature all five grid illusions included.

Installation

Users must install the following Python software to use PyGrid:

pip install pillow

Install directly from this GitHub repository in Python terminal:

pip install https://github.com/OliverACollins/PyGrid/zipball/main

Illusions included in this package

Here, you can find the five illusions included in PyGrid, which can be generated either in the CLI or directly within Python scripts.

Note

Many of the illusions shown in the images below may not produce an illusory effect here due to their relatively small display sizes.

Hermann grid illusion

First described by Brewster in 18441, although generally attributed to Hermann (1870)2, the Hermann grid illusion is prototypically created when looking at a white grid on top of a black background. The optical illusion experienced consists of deceptively seeing relatively faint dark patches appearing at the intersections of the grid lines.

Default and reverse contrast Hermann grid illusions

PyGrid hermann
from grid_illusions.hermann import draw_hermann

img = draw_hermann(
    illusion_size=(600, 600),
    cells=(5, 5),
    line_width=12,
    line_colour="blue"
)

img.show()
img.save("hermann.png")

Scintillating grid illusion

Documented in the 1990s3, this illusion is commonly generated by placing a grey grid on top of a black background, with white dots positioned at the intersections of the vertical and horizontal grid lines. As one's eyes move around the grid, it appears as though the dots are twinkling between white and black.

Default and distorted scintillating grid illusions

PyGrid scintillating
from grid_illusions.scintillating import draw_scintillating

img = draw_scintillating(
    illusion_size=(600, 600),
    cells=(12, 12),
    line_width=6,
    line_colour="blue"
)

img.show()
img.save("scintillating.png")

Bergen grid illusion

The Bergen grid illusion4 comprises a blurred Hermann grid, which creates a scintillating effect at the grid intersections. In this example, the grid lines are grey as opposed to being in their prototypical Hermann grid white.

Default and distorted Bergen grid illusions

PyGrid bergen
from grid_illusions.bergen import draw_bergen

img = draw_bergen(
    illusion_size=(600, 600),
    line_width=8,
    line_colour="blue"
)

img.show()
img.save("bergen.png")

Ninio's extinction illusion

Gaining some media attention back in 20165, Ninio's extinction illusion6 comprises 12 black dots laid at the intersections of the grey vertical, horizontal, and diagonal lines. Try to view all 12 black dots at once!

Default and colour-changed Ninio's grid illusions

PyGrid ninio
from grid_illusions.ninio import draw_ninio

img = draw_ninio(
    illusion_size=(800, 575),
    line_width=8,
    line_colour="blue"
)

img.show()
img.save("ninio.png")

McAnany-Levine's extinction illusion

Producing a particularly powerful effect, the default McAnany-Levine extinction illusion7 is created by overlaying 13 white dots at the intersections of the grey vertical and horizontal grid lines. You will not be able to perceive all 13 dots simultaneously!

Default and colour-changed McAnany-Levine grid illusions

PyGrid mcanany-levine
from grid_illusions.mcanany_levine import draw_mcanany_levine

img = draw_mcanany_levine(
    illusion_size=(600, 600),
    line_width=8,
    dot_colour="red"
)

img.show()
img.save("mcanany_levine.png")

Parameters

There are a number of parameters that can be set for each grid illusion, such as to vary the strength of an illusion. Examples of these arguments include:

  • cells: set the number of cells on each side of the grid (although, this argument will be influenced visually by the grid_zoom argument by default)
  • illusion_size: determine the size of the grid illusion (in pixels)
  • grid_zoom: apply a zoom function to the grid to create a more natural appearance
  • line_width: specify the width of the grid lines (all vertical, horizontal, and diagonal dimensions)
  • line_colour: change the colour of the grid lines. Here, as with any of the colour arguments, you can use HTML colour names or HEX codes, ensuring that such HEX codes are specified as a string
  • wiggle_amplitude and wiggle_frequency: the former controls the displacement of the distortion applied to the grid lines, and the latter manipulates the number of waves in the grid lines when distorted. It is important to note that, to create a distorted grid, BOTH "wiggle" arguments must be used in conjunction
  • blur_strength: control the Gaussian blur applied to the image (mostly relevant to the Bergen illusion)
  • save: change the file name (and file path) for the illusion image. It is crucial to specify the file extension (e.g., .png, .jpg, .pdf)

Note

Many of these parameters operate orthogonally, meaning that a change in one argument will not result in proportionate changes to other arguments.

To view the parameters included for each grid illusion, simply use the --help option in the Python terminal to read a brief description of what each argument does and its default setting:

PyGrid hermann --help

In the Python terminal, parameters can be specified in the following manner:

PyGrid hermann --cells (8, 8) --illusion_size (300, 300) --line_width 10 --line_colour blue

If any issues with this Python package occur, please open an Issue so that any problems highlighted can be addressed. Thank you!

References

Footnotes

  1. Brewster, D. (1844). A notice explaining the cause of an optical phenomenon observed by the Rev. W. Selwyn. Report of the British Association for the Advancement of Science, Transactions of the Sections, 8.

  2. Hermann, L. (1870). Eine Erscheinung simultanen Contrastes. Pflüger, Archiv für die Gesammte Physiologie des Menschen und der Thiere, 3(1), 13–15. https://doi.org/10.1007/BF01855743

  3. Schrauf, M., Lingelbach, B., Lingelbach, E., & Wist, E. R. (1995). The Hermann grid and the scintillation effect. Perception, 24(Suppl.), 88–89.

  4. Bergen, J. R. (1985). Hermann's grid: new and improved (abstract). Investigative Ophthalmology and Visual Science (Supplement), 26, 280.

  5. BBC. (2016, September 12). How many spots can you see in this optical illusion? https://www.bbc.co.uk/news/science-environment-37337778

  6. Ninio, J., & Stevens, K. A. (2000). Variations on the Hermann grid: An extinction illusion. Perception, 29(10), 1209–1217. https://doi.org/10.1068/p2985

  7. McAnany, J. J., & Levine, M. W. (2010). The vanishing disk; a revealing quirk of the scintillating grid illusion. Journal of Vision, 2(7), 204–204. https://doi.org/10.1167/2.7.204

About

A Python package enabling users to generate several different grid illusions, including the classic Hermann and scintillating grid illusions

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages