Tracing multiple shapes on the same screen with Spyrograph
Tags: python, showdev, opensource, contributorswanted
Published: 2023-04-08 14:00:00

_DISCLAIMER: This blog post was written by a human with the help of AI_

## Introduction <a src="#introduction"></a>
In this tutorial, we'll demonstrate how to chain screens for multiple traces, allowing us to create captivating artwork by layering different spirograph shapes on the same canvas with Spyrograph!

Follow along as we use a custom code snippet to showcase this technique in action

- [Introduction](#introduction)
- [Creating our first spirograph](#creating-our-first-spirograph)
- [Tracing the first shape](#tracing-the-first-shape)
- [Creating a second shape](#creating-a-second-shape)
- [Trace the second shape on the same screen](#trace-the-second-shape-on-the-same-screen)
- [Experiment with different shapes and colors](#experiment-with-different-shapes-and-colors)
- [Conclusion](#conclusion)

{% github https://github.com/chris-greening/spyrograph %}

---

## Creating our first spirograph <a src="#creating-our-first-spirograph"></a>
To begin, let's create our first spirograph shape using the `Hypotrochoid` class. Import the necessary libraries and define the required parameters for the shape

```python
from spyrograph import Hypotrochoid
import numpy as np

first_shape = Hypotrochoid(
    R=233,
    r=200,
    d=233,
    thetas=np.arange(0, 100*np.pi, .5)
)
```

---

## Tracing the first shape <a src="#tracing-the-first-shape"></a>
Next, trace the first shape and keep the screen open by calling the `trace` method. By default, the `exit_on_click` option is set to False, which ensures that the `screen` remains active after tracing the first shape

```python
screen, turtles = first_shape.trace()
```

![A black tracing is drawn on white background](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k6endpamgbf5sl2e9g61.PNG)

---

## Creating a second shape <a src="#creating-a-second-shape"></a>
Now, let's create a second shape by using the `scale` method to adjust the size of the first shape into a  slightly smaller copy

```python
second_shape = first_shape.scale(.85)
```

---

## Trace the second shape on the same screen <a src="#trace-the-second-shape-on-the-same-screen"></a>
Trace the second shape on the same screen by passing the existing `screen` to the `trace` function. Additionally, set the `exit_on_click` option to `True` and choose a different `color` for the second shape

```python
second_shape.trace(
    exit_on_click=True,
    color="red",
    screen=screen
)
```
![A copy of the first shape is traced on the same screen but slightly smaller and in red](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3f81f2vc8cf7oz1wdv08.PNG)

---

## Experiment with different shapes and colors <a src="#experiment-with-different-shapes-and-colors"></a>
Feel free to experiment with different shapes, sizes, and colors to create your unique spirograph artwork. You can create and layer multiple shapes on the same screen by following the steps outlined above

---

## Conclusion <a src="#conclusion"></a>
Chaining screens for multiple traces is a powerful technique to create visually stunning spirograph designs

By layering different shapes and colors on the same canvas, you can produce eye-catching and intricate artwork

Don't be afraid to explore various patterns and unleash your creativity with Spyrograph!