Stretch discs/circles into squares and squish squares into discs/circles
Project description
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 insall squircle
Usage:
from squircle import to_circle, to_square
from PIL import Image
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/
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
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file squircle-0.2.0.tar.gz
.
File metadata
- Download URL: squircle-0.2.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.8.0a3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8bed5744078fd8b4dcac29bec0804f87e32a17c8cb2ec0718f00263cbbae6b12 |
|
MD5 | 3d24ba01c22623b05d231214afc5c6e6 |
|
BLAKE2b-256 | 2444e718fd9f4e44b47a54f41b836917e51ac666da5180876748c9c149476205 |