A flexible Python package enabling users to draw several different grid illusions.
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.
Users must install the following Python software to use PyGrid:
pip install pillowInstall directly from this GitHub repository in Python terminal:
pip install https://github.com/OliverACollins/PyGrid/zipball/mainHere, 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.
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.
PyGrid hermannfrom 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")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.
PyGrid scintillatingfrom 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")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.
PyGrid bergenfrom 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")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!
PyGrid niniofrom 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")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!
PyGrid mcanany-levinefrom 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")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 thegrid_zoomargument 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 appearanceline_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 stringwiggle_amplitudeandwiggle_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 conjunctionblur_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 --helpIn 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 blueIf any issues with this Python package occur, please open an Issue so that any problems highlighted can be addressed. Thank you!
Footnotes
-
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. ↩
-
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 ↩
-
Schrauf, M., Lingelbach, B., Lingelbach, E., & Wist, E. R. (1995). The Hermann grid and the scintillation effect. Perception, 24(Suppl.), 88–89. ↩
-
Bergen, J. R. (1985). Hermann's grid: new and improved (abstract). Investigative Ophthalmology and Visual Science (Supplement), 26, 280. ↩
-
BBC. (2016, September 12). How many spots can you see in this optical illusion? https://www.bbc.co.uk/news/science-environment-37337778 ↩
-
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 ↩
-
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 ↩





