DISCLAIMER: This blog post was written by a human with the help of AI
When working with the spyrograph
package, we often want to create a range of different shapes by varying one of the input parameters while keeping the others constant
This is where the create_range
class method comes in handy!
In this blog post let's walk through how to use the create_range
method to generate a list of instantiated Hypotrochoid
objects with varying input parameters
Table of Contents
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β¦
Understanding the create_range
method
The create_range
method allows us to create a range of different hypotrochoids and epitrochoids by varying one of the input parameters (R
, r
, or d
) while keeping the others constant
This method accepts the following parameters:
-
R
: The radius of the fixed circle, either a single number or a list of numbers. -
r
: The radius of the rolling circle, either a single number or a list of numbers. -
d
: The distance of the trace point from the rolling circle, either a single number or a list of numbers. -
thetas
: An optional list of values for theta for inputting into parametric equations. -
theta_start
: An optional starting theta value for creating a list of thetas. -
theta_stop
: An optional stop theta value for creating a list of thetas, where the stop value is not included in the final array. -
theta_step
: An optional incremental step value for stepping from start to stop. -
origin
: An optional custom origin to center the shapes at, with the default being (0, 0).
The method returns a list of instantiated Hypotrochoid
objects where one of the input parameters is a list of increments and the others are fixed
Using the create_range
method
Let's say we want to create a range of hypotrochoids with varying radii of the rolling circle (r
) while keeping the radii of the fixed circle (R
) and the distance of the trace point from the rolling circle (d
) constant
To do this we can use the create_range
method as follows:
from spyrograph import Hypotrochoid
import numpy as np
import turtle
arr = Hypotrochoid.create_range(
R=600,
r=np.arange(295,300,.2),
d=51,
theta_start=0,
theta_stop=35*np.pi,
theta_step=.1
)
Now, hypotrochoids contains a list of Hypotrochoid
objects with varying r
values
We can then use the trace
method to visualize these shapes:
screen = None
for shape in arr:
screen = shape.trace(
screen=screen,
color="white",
screen_color="black"
)
turtle.exitonclick()
This will display the hypotrochoids one after the other on the same screen resulting in a more complex looking image
Conclusion
In this post, we explored the powerful create_range
method provided by the spyrograph
package, which allows us to generate a wide variety of beautiful hypotrochoids and epitrochoids with just a few lines of code
By specifying a range of values for R
, r
, or d
we can quickly create and visualize multiple shapes, making it an excellent tool for artists, educators, and anyone interested in exploring the fascinating world of spirograph patterns
With spyrograph
, the possibilities for creating captivating designs are virtually endless - we hope this method inspires your creativity and leads to the discovery of stunning spirograph patterns unique to you!
Top comments (0)