Sunday 6 December 2015

My Prime Dragon

So yesterday I was filled with a sense of ennui, so I cast my brain about, trying to find something interesting to think about. Something I could do. Eventually, I came across a graph of sorts that I wanted to investigate. The process is simple:

Draw a short line segment. Look at the number 2. If it is prime, turn left and draw a short segment, if it isn't prime, then turn right and draw a small segment. Then look at the number 3, and 4, and so on and so forth.

I coded a little thing in Python, to see what it looked like, but because every second number is even (and hence not prime), it was really regular, and it didn't really appeal that much to me.

This 'Blue Prime Dragon' is what occurred when I included all the even numbers. Because even numbers are all not prime, every second number would result in a turn to the right. This (quite amazingly actually) constrains the dragon to a rod like path. The little segment sticking out of the rod near the bottom is the origin, and only occurs because 2 is even, yet it is a prime. 

So to spruce my Prime Dragon up a bit, I simply only looked at the odd numbers, and I got quite a few nice patterns out. I then dubbed the creation a "Prime Dragon" (sounds cool to me).

This is the first thousand or so steps of the Prime Dragon. Pretty neat, huh!

Anywhoo, here's the python code:
https://drive.google.com/file/d/0B8DUM8AhrXqKQ0YtU0RtUk41VHc/view?usp=sharing
https://drive.google.com/file/d/0B8DUM8AhrXqKVE1BaUxNNmJndU0/view?usp=sharing
https://drive.google.com/file/d/0B8DUM8AhrXqKS3dPZDBZUzZUMjQ/view?usp=sharing
-just in case someone wanted to know (I know nobody but me gonna read this lol)

Before I hit the bed, here's some still shots:
from One to a thousand

from One to ten thousand



One to a hundred thousand

The graphics side of things is just painful. I was using the svgwrite python library to create svg files. It worked fine, in that I could create still images of my dragon. But I wanted to create an animation (like the gif shown at the top of this post, from one to a thousand steps). And no matter what I tried, it just wouldn't work. In the end, I just created a separate svg file for every frame, and used Paint.net to stitch them together into one gif. Truly, a painful process. Maybe I'll write my own python SVG writer library. Also, my original problem was like "if I take n to infinity, is the Prime Dragon bounded or not' (does it extend to infinity?). My intuition says no, but it feels like it could be yes, though I'm too noob to know. I'll think about it a bit later. Its late. 




No comments:

Post a Comment