Scaling trochoid’s and cycloid’s input parameters with the spyrograph `scale` method

DISCLAIMER: This blog post was written by a human with the help of AI

In this blog post, we will explore the scale method in the spyrograph package which enables users to easily scale their trochoid’s and cycloid’s input parameters

Scaling trochoid’…


This content originally appeared on DEV Community and was authored by Chris Greening

DISCLAIMER: This blog post was written by a human with the help of AI

In this blog post, we will explore the scale method in the spyrograph package which enables users to easily scale their trochoid's and cycloid's input parameters

  • Scaling trochoid's and cycloid's input parameters with the spyrograph scale method
  • Creating a Hypocycloid
  • Scaling the Hypocycloid with the scale method
  • Using scale to trace a beautiful pattern
  • Conclusion

GitHub logo 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

Animation of three geometric, symmetrical shapes being drawn next to one another left to right. The shape on the left is red, the middle green, and the right is blue.

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

Downloads Issues License Version

"Buy Me A Coffee"

Official website

Official docs

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

Sample hypotrochoid drawing showing a circle rolling around the interior of another circle drawing a geometric shape

Table of Contents

đź’» 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 in just a…




Creating a Hypocycloid

First, let's create a Hypocycloid with 10 cusps to work with:

import numpy as np
from spyrograph import Hypocycloid

hypocycloid = Hypocycloid.n_cusps(
    R=300,
    n=10,
    thetas=np.arange(0, 2*np.pi, .1)
)

A circular shape with 20 cusps is drawn by a circle rolling around the interior of another fixed circle

Scaling the Hypocycloid with the scale method

Now that we have a Hypocycloid, we can easily scale it using the scale method:

scaled_hypocycloid = hypocycloid.scale(factor=.5)

A circular shape with 20 cusps is drawn by a circle rolling around the interior of another fixed circle and then an identical shape that is half the size is drawn right in the center

The scaled_hypocycloid will now have its input parameters (R, r, and d) multiplied by the scaling factor

For example the radius of the big circle R=300 will now be R*.5=150

Using scale to trace a beautiful pattern

Let's jump into a concrete example of using the scale method in action to trace a gradually smaller set of curves

from spyrograph import Hypocycloid
import numpy as np
import time

screen = None
hypocycloid = Hypocycloid.n_cusps(
    R=200,
    n=20,
    theta_start=0,
    theta_stop=2*3.1415,
    theta_step=.01
)
for i in range(1,40):
    screen = hypocycloid.trace(screen=screen)
    hypocycloid = hypocycloid.scale(factor=((40/(i+40))))
    time.sleep(.1)
turtle.exitonclick()

A circular shape with 20 cusps is drawn and then a slightly smaller one is drawn within that and then this continues down until a shape that resembles a spiderweb is drawn

Conclusion

The scale method in spyrograph provides a convenient way to resize trochoids and cycloids while preserving their shape

With just a single method call and a scaling factor, users can quickly create new shapes with different sizes, making the package even more versatile for artists, educators, and developers alike

Don't forget to experiment with different scaling factors and shapes to create stunning patterns and visuals!


This content originally appeared on DEV Community and was authored by Chris Greening


Print Share Comment Cite Upload Translate Updates
APA

Chris Greening | Sciencx (2023-04-01T14:00:00+00:00) Scaling trochoid’s and cycloid’s input parameters with the spyrograph `scale` method. Retrieved from https://www.scien.cx/2023/04/01/scaling-trochoids-and-cycloids-input-parameters-with-the-spyrograph-scale-method/

MLA
" » Scaling trochoid’s and cycloid’s input parameters with the spyrograph `scale` method." Chris Greening | Sciencx - Saturday April 1, 2023, https://www.scien.cx/2023/04/01/scaling-trochoids-and-cycloids-input-parameters-with-the-spyrograph-scale-method/
HARVARD
Chris Greening | Sciencx Saturday April 1, 2023 » Scaling trochoid’s and cycloid’s input parameters with the spyrograph `scale` method., viewed ,<https://www.scien.cx/2023/04/01/scaling-trochoids-and-cycloids-input-parameters-with-the-spyrograph-scale-method/>
VANCOUVER
Chris Greening | Sciencx - » Scaling trochoid’s and cycloid’s input parameters with the spyrograph `scale` method. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2023/04/01/scaling-trochoids-and-cycloids-input-parameters-with-the-spyrograph-scale-method/
CHICAGO
" » Scaling trochoid’s and cycloid’s input parameters with the spyrograph `scale` method." Chris Greening | Sciencx - Accessed . https://www.scien.cx/2023/04/01/scaling-trochoids-and-cycloids-input-parameters-with-the-spyrograph-scale-method/
IEEE
" » Scaling trochoid’s and cycloid’s input parameters with the spyrograph `scale` method." Chris Greening | Sciencx [Online]. Available: https://www.scien.cx/2023/04/01/scaling-trochoids-and-cycloids-input-parameters-with-the-spyrograph-scale-method/. [Accessed: ]
rf:citation
» Scaling trochoid’s and cycloid’s input parameters with the spyrograph `scale` method | Chris Greening | Sciencx | https://www.scien.cx/2023/04/01/scaling-trochoids-and-cycloids-input-parameters-with-the-spyrograph-scale-method/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.