Skip to main content

squircle.py is a Python 3 utility for stretching discs/circles into squares and squishing squares into discs/circles

Usage:

from squircle import to_disc, to_square
from PIL import Image

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

there's 3 stretching methods you can choose from

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

Stretching methods

Fernández-Guasti squircle (fgs)

The Fernández-Guasti squircle (fgs) 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 allegedly difficult.

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

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


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

Squircle doesn't handle ellipses/rectangles, this more recent paper should be useful: Elliptification of Rectangular Imagery by C Fong - ‎2017

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

squircle-0.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

squircle-0.0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file squircle-0.0.1.tar.gz.

File metadata

  • Download URL: squircle-0.0.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for squircle-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d5d7c3c1fce0d1bd5e93c9600df498688f25e048f80010772b765d1ef43d4784
MD5 586a1d6d26e480b7a671ac4f120e803e
BLAKE2b-256 048fbb5737dac3b563442f6094a2bd3d9f6781aebf865f904c8ca8932e4d758d

See more details on using hashes here.

File details

Details for the file squircle-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: squircle-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for squircle-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d33c38bef0760dd2e412d82a88db8ad900e332778b5d4023d9fed4b6753c2922
MD5 fbe65f1e27091a6fd0c80cd41c628164
BLAKE2b-256 cb54df0d2100e738a79c3f14ff1db9b01490323a30c6559230d092eab444ceab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page