Skip to main content

squircle.py is a Python utility for stretching circles into squares and squishing squares into circles. It requires Python 3.6 or later.

Installation

pip install squircle

Usage:

import numpy as np
from PIL import Image

from squircle import to_circle, to_square

square = np.asarray(Image.open('some-square-image.jpg'))
circle = to_circle(square)
and_back_to_square = to_square(circle)

there's 3 stretching methods you can choose from

>>> from squircle import methods
>>> list(methods.keys())
['fgs', 'stretch', 'elliptical']
>>> circle = to_circle(square, method='elliptical')

Stretching methods

Fernández-Guasti squircle (fgs)

The Fernández-Guasti squircle is used by default.

https://squircular.blogspot.com/2015/09/fernandez-guastis-squircle.html

http://mathworld.wolfram.com/Squircle.html

Simple Stretching (stretch)

This method "just linearly stretches each point radially so that the rim of the circle matches the rim of the square".

https://squircular.blogspot.com/2015/09/elliptical-arc-mapping.html

Elliptical grid mapping (elliptical)

"The way I went about this was to think of a line of constant x (as well as a line of constant y) getting mapped to an ellipse in the circle"

https://mathproofs.blogspot.com/2005/07/mapping-square-to-circle.html

https://squircular.blogspot.com/2015/09/mapping-circle-to-square.html

Schwarz-Christoffel conformal mapping

raise NotImplementedError. The math is difficult.

https://squircular.blogspot.com/2015/09/schwarz-christoffel-mapping.html

http://jcgt.org/published/0005/02/01/

Development

After pip install tox you can run squircle's (limited) test set with

tox

On Ubuntu, you also need the following dependencies for numpy and matplotlib

sudo apt install python3-dev libjpeg-dev zlib1g-dev libfreetype6-dev

You can visually inspect the transformations by uncommenting the matplotlib code in test_squircle.py and then invoking the tests directly with pytest instead of tox

pytest

but you'll need to install the dependencies of the tests manually, which you can do with pip install pytest numpy matplotlib pillow.

TODOs

If you would like to help with this project, the open issues on GitHub should list some ideas.

Credits

This code is converted from the C++ sources on Chamberlain Fong's blog posts, which (I think) are based on his paper Analytical Methods for Squaring the Disc (2014).

The square image in test_images/ is https://commons.wikimedia.org/wiki/File:Graph-paper.svg and the circle is taken from Chamberlain Fong's blog posts.

Metadata

Release files for squircle 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for squircle 0.2.2
File Size Uploaded Provenance
squircle-0.2.2.tar.gz 5.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for squircle 0.2.2
File Interpreter ABI Platform
squircle-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 11.0 kB

Release files / squircle-0.2.2.tar.gz

Download URL squircle-0.2.2.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
732090b448603386f49f809cb8914d4b900ab54d260f267d09190ae4c6dabdec
BLAKE2b-256 checksum
How to use checksums
057e654bbf39d6d606b9787867d3e948d36dd9e61e8cb2ca753f1498fead99d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0+

Release files / squircle-0.2.2-py3-none-any.whl

Download URL squircle-0.2.2-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5e7e72cfe37b91c4a4c823eb6fba8c2aef80c0ed3c15ffe08aacaa56e9f6207
BLAKE2b-256 checksum
How to use checksums
a870e1fb3b0bd4717befe1023440b037cd7ac6901a2e75844e022b11b1a34b53
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0+

Security for squircle 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page