Customizing the origin of our geometric visualizations using Python and Spyrograph
Chris Greening
Posted on April 10, 2023
DISCLAIMER: This post was written by a human with the help of AI
Introduction
Trochoids and cycloids are beautiful geometric shapes generated by tracing a point on a rolling circle as it moves around a fixed circle - these shapes have captivated artists, mathematicians, and enthusiasts for centuries with their elegant, geometric patterns
These mesmerizing patterns, often seen in spirograph designs, offer endless possibilities for exploration and creativity. One of the most powerful ways to customize and control the appearance of trochoid curves is by adjusting the origin β the central point around which the entire pattern revolves
In this blog post, we will delve into the concept of customizing the origin in our designs uncovering its role in the shape's geometry and its impact on the final design. We will explore various techniques to shift and manipulate the origin, as well as demonstrate how combining multiple trochoid shapes with different origins can result in intricate and visually stunning patterns
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
Understanding the role of the origin in trochoid curves
Before diving into the process of customizing the origin, it's essential to understand its role in trochoid curves. The origin serves as the central point around which the entire pattern revolves. It determines the position of the fixed circle and, consequently, influences the trajectory of the rolling circle and the trace point
See the animation below as an example where the bright green dot is the origin:
By default, the origin is set at the coordinate (0, 0), placing the fixed circle's center at this location. However, by customizing the origin, we can shift the entire pattern to a different point in the Cartesian plane, thus altering the position of the trochoid curve
Keep in mind that changing the origin only affects the position of the pattern, not its shape or size. To modify the trochoid curve's actual geometry, you would need to adjust other parameters such as the radii of the fixed and rolling circles (R, r) or the distance (d) of the trace point from the rolling circle
Customizing the origin
Now that you have a clear understanding of the role of the origin in spirographs, let's walk through the steps to customize it. The process is quite straightforward, as you only need to modify the origin parameter when creating your shape (i.e. Hypotrochoid, Epicycloid, etc.)
Choose the new origin
First, decide on the new origin coordinates you want to use for your trochoid curve. These coordinates should be a tuple of two numbers representing the x and y values, e.g., (x, y)
Create a trochoid curve with the custom origin
When creating a new shape, pass the chosen origin coordinates as the origin parameter
For example the following code snippet creates a Hypotrochoid with a custom origin at the point (100, 100) instead of the default (0, 0):
This results in the tracing being translated to the right 100 pixels and then up 100 pixels as shown below where the black tracing is at the default (0, 0) and the red tracing is at (100, 100)
Visualize the curve
After creating the trochoid curve with the custom origin, you can visualize it using the trace method. The custom origin will be taken into account when drawing the pattern, and the fixed circle's center will be placed at the specified origin.
shape.trace(exit_on_click=True)
Combining multiple trochoid shapes with different origins
Incorporating multiple trochoid shapes with different origins into a single design can create stunning, complex patterns. Here's a step-by-step guide on how to combine multiple trochoid shapes with different origins:
Create individual trochoid shapes
Start by creating each trochoid shape with its unique parameters (R, r, d, and thetas). Make sure to also set the origin for each shape, as this will determine its position relative to the other shapes.
To draw the shapes on the same screen, use the trace method for each shape and capture the returned turtle.Screen as a variable to pass into the next trace call to persist the designs onto the same screen. Note that the screen configurations defined in your first trace will determine how the screen looks for subsequent trace's (see this post for more info)
Feel free to modify the parameters, colors, and origins of each shape to create unique and interesting patterns. By changing the origins, you can position the shapes in various ways, such as stacking them, creating a grid, or designing a mosaic.
By following these steps, you can create intricate designs that combine multiple shapes with different origins. This technique offers endless possibilities for creativity and customization, allowing you to produce stunning visual displays
Example: Creating a complex spirograph design by varying the origin
Manipulating the origin of trochoid shapes can produce intricate and fascinating spirograph patterns. In this section we will use a for loop to draw 25 Hypotrochoid's, each shifted slightly to the right compared to the previous iteration of the loop. We will also modify the color starting from black and slightly lighten the hex color towards white to give an interesting fade effect:
Selecting the right origin for your trochoid shapes can make all the difference in creating captivating spirograph designs. Here are some tips and tricks to help you choose the perfect origin for your creations:
Consider symmetry
Symmetry is often visually pleasing and can create a sense of balance in your designs. When choosing the origin for multiple shapes, try to create symmetrical patterns by aligning the shapes relative to one another.
Offset shapes for contrast
By setting the origin of different shapes with an offset, you can create striking contrasts that make each shape stand out. This technique can be particularly effective when you're working with shapes that have similar parameters but different colors.
Think about screen size and aspect ratio
Keep in mind the size and aspect ratio of the screen or canvas on which you plan to display your design. Choose origins that fit comfortably within the available space and avoid placing shapes too close to the edges to prevent clipping or distortion
Trial and error
Don't be afraid to experiment with different origins. Sometimes, the best designs emerge from unexpected combinations. Adjust the origin of your shapes, observe the results, and fine-tune your choices until you achieve the desired effect.
Opt for automation
If you're working with a large number of shapes or seeking a more randomized design, consider writing a script to automate the process of selecting origins. For example, you can use a loop or a random number generator to create a grid or a circular arrangement of shapes.
Look at existing spirograph designs, mandalas, or geometric patterns for inspiration when choosing the origins for your shapes. You can replicate or modify these designs, or use them as a starting point to develop your own unique creations.
Keep it simple
Sometimes, simplicity is key. You don't always need to choose complex origins or create intricate patterns to make a visually appealing design. Experiment with a single shape or a small number of shapes and see how changing the origin affects the overall appearance.
By keeping these tips and tricks in mind when choosing the origin for your trochoid shapes, you can create visually captivating spirograph designs that showcase your creativity and artistic flair.