summary refs log tree commit diff
path: root/How-to/Python/Envelope (mathematics) generator/index.md
blob: 79e92de0426384b20d62343337784d29f1dd6d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
description: Generating geometric line art
created: 2024-05-12
---

![Envelope](Envelope.png)

Needed a clean picture of [Envelope (mathematics)](https://en.wikipedia.org/wiki/Envelope_%28mathematics%29), 
for PCB silk screen art.
I used [Python Pillow](https://python-pillow.org/)
```
pip install pillow~=10.3
```

```python
from PIL import Image, ImageDraw

# https://en.wikipedia.org/wiki/Envelope_%28mathematics%29

dim = 200  # Image dimensions (pixels)
skip = 10   # Only draw a line every X pixels
width = 1   # Line width
color = "white"

with Image.new(mode = "RGB", size = (dim, dim)) as im:  # mode="RGBA" for transparent background
    draw = ImageDraw.Draw(im)

    for i in range(dim):
        if i % skip:
            continue
        rev = dim - i
        draw.line([(0, i), (i, dim)], fill=color, width=width) 
    
    im.show()  # im.save("/tmp/Envelope.png")
```