Okay, so today I wanted to mess around with generating some geometric patterns, specifically hexagrams. I’ve always been fascinated by the shapes and how they’re used in different cultures and, you know, just thought it’d be fun to try and create some myself.
Getting Started
First things first, I needed a way to actually draw the thing. I figured Python with the Turtle library would be a good, simple way to go. It’s like a little digital pen that you can command to move around and draw lines. I’ve used it before for basic stuff, so I felt pretty comfy with it.
Now, the tricky part: figuring out the angles and distances to actually draw a hexagram. I kinda remembered it’s basically two overlapping triangles, but getting the specifics right took some fiddling. My first few attempts? Let’s just say they weren’t pretty. Lots of weird, squiggly lines that looked nothing like a hexagram.
I started with, I think, 120-degree turns, because that’s what I vaguely remembered from, like, high school geometry. Nope. Too wide. Then I tried smaller angles, bigger angles… Honestly, it was a lot of just running the code, seeing a mess, changing a number, and running it again.
Finally, Some Progress!
After a bunch of tries, I landed on using a 60-degree turn for the inner triangle and a 120-degree turn to jump to the next point of the outer triangle. And… it started to look like something! It wasn’t perfect, but it was definitely a hexagram-ish shape.
for i in range(3):
*(100)
*(120)
*(60)
for i in range(3):
*(100)
*(120)
Making it Look Nicer
I add some colors and faster the turtle speed.
*(10)
*("blue")
The (Almost) Final Result
And below the complete code and it creates Hexagram 5:
import turtle
screen = *()
pen = *()
*(10)
*("blue")
for i in range(3):
*(100)
*(120)
*(60)
for i in range(3):
*(100)
*(120)
It’s not the most amazing piece of code ever written, but it was a fun little exercise. And it reminded me how much I enjoy that feeling of finally figuring something out after a bunch of failed attempts. It’s like, “Aha! I knew I could do it!” Plus, I got a cool little hexagram out of it.