DISCLAIMER: This blog post was written by a human with the help of AI
In this blog post, we will explore a powerful feature of the spyrograph
package: the ability to create and draw cycloids with a specified number of cusps
Cycloids are special cases of trochoids where the distance parameter d
is equal to the rolling circle radius r
By using the n_cusps
class method provided in the Hypocycloid
and Epicycloid
classes, we can easily create beautiful cycloid shapes with a desired number of cusps
Table of contents
- Prerequisite imports
- Creating a cycloid with a specified number of cusps
- Tracing the cycloid with
trace
- Conclusion
chris-greening / spyrograph
Python library for analyzing, exploring, and visualizing epitrochoids and hypotrochoids in just a few lines of code
spyrograph: elegant mathematics and geometries
What is it?
spyrograph is a lightweight Python package that provides an expressive and flexible set of tools for drawing beautiful mathematically driven art. With just a few lines of easy-to-read code you can start analyzing, visualizing, and exploring elegant mathematics
Table of Contents
π Key features
- Expressive and consistent syntax
- Robust underlying mathematics
- Beginner and expert friendly
-
numpy
is the only required third-party installation - Clear visualizations and animations
- Flexible to a wide range of usecases
- Lightweight, just plug and play
π» Installation
pip
Install the latest stable release from PyPI using
$ pip3 install spyrograph
or clone the development version from GitHub with
$ git clone https://github.com/chris-greening/spyrograph.git
π± Quickstart
spyrograph
is designed to be expressive and easy-to-use - simply import spyrograph
and jump right into drawing elegant, complex shapesβ¦
Prerequisite imports
Before we begin, let's make sure we have the spyrograph
package installed:
pip3 install spyrograph
Creating a cycloid with a specified number of cusps
To create a cycloid with a specified number of cusps, we can use the n_cusps
class method. Here's a quick example of how to create a hypocycloid with 5 cusps:
from spyrograph import Hypocycloid
import numpy as np
R = 50
n = 5
thetas = np.arange(0, 2 * np.pi, 0.01)
hypocycloid = Hypocycloid.n_cusps(R=R, n=n, thetas=thetas)
In this example, we set the radius of the fixed circle R
to 50
and the desired number of cusps n
to 5
. The n_cusps
method calculates the rolling circle radius r
as R/n
and instantiates a cycloid object with the provided parameters
Tracing the cycloid with trace
Now that we have created a hypocycloid with 5 cusps, let's trace it using the trace
method provided by the spyrograph
package
hypocycloid.trace(exit_on_click=True)
The trace
method will display an animation of the cycloid shape being drawn
The exit_on_click
argument ensures that the animation window remains open until you click on it
Conclusion
The n_cusps
class method in the Hypocycloid
class is a powerful and easy-to-use feature for creating and drawing cycloid shapes with a specified number of cusps
By using this method, artists and educators alike can create visually stunning and mathematically precise cycloids in a matter of seconds
Give it a try and unlock your creativity with the spyrograph
package today!
Top comments (0)