0
One of the things I like about the pixel stick is that you can get some really beautiful and complex patterns from what seem like very simple images. The image below is simply a few circles overlaid in a row, spinning the pixel stick as you walk. Rest assured, this wasn’t my first attempt.

Symmetrical-ish

Going polar

Playing with circles got me to thinking: you could double the resolution of the image if you used one end of the stick as the centre of a circle and drew around it. Obviously, if you take an image and just spin it around, that’s not going to come our right – though, thinking about it, I might give that a go as well. So, without really knowing what I was looking for, I happened across the concept of polar coordinates. I’m not a mathematician, I just like a bit of maths when it helps me do what I want to do, so this is my explanation…

What are polar coordinates?

Polar coordinates are just a different way of representing x and y coordinate but, instead of x, you have distance from a central point and, instead of y, you have the angle of rotation from a starting point. Working on that basis, I wrote a little Python script to convert a 400×400 image into an image 200 pixels tall and 1260 pixels wide. The circumference of a circle 400 pixels wide is 1257, and I wanted one pixel for each ‘unit’ of the circumference. I rounded up to the nearest multiple of 4, because that comes in later.

If you’re not interested in trying this kind of thing for yourself, then you can probably just skip this section and look at any pictures at the end. I’ve recently started programming in Python; I like its structure and simplicity. I’m also a problem solver rather than a packager, so my code, in this case, is just run from within Eclipse, I haven’t packaged it in any way. I haven’t exhaustively commented the code, as I’ll try to explain what I’m doing in the text.

'''If you use a variant of this code, please give me attribution by leaving this comment section intact. This code is intended for use in converting a 400x400 circular image into a rectangular image that can be rotated around one edge to recreate the original. It was created by Chris Geatch as part of www.disproportionart.co.uk. You can also find his photography on flickr at https://www.flickr.com/photos/geatchy
from PIL import Image as im
import math
stick_width = 1260 #This is the width of the final image to load to the pixel stick

You’ll need the PIL library for image processing, if you don’t have it already. There are all sorts of guides to installing it, so I’ll leave you to choose one for yourself.

def main():
processImage("G:\\image path\\", "rbogrid.jpg")
def get_coordinate(stick_x,stick_y,centre_x,centre_y):
angle = (stick_x / stick_width) * (2 * math.pi)
return angle
def processImage(image_path, image_name):
image_title = image_name[0:image_name.find(".")]
image = im.open("%s\\%s" % (image_path, image_name),"r")
im_stick = im.new("RGB", (stick_width,200), color="#000000")
for stick_x in range(stick_width):
for stick_y in range(200):
hypotenuse = 1.0 * stick_y #The distance from the polar centre
quadrant = int(stick_x / (stick_width/4))
theta = (((1.0 * stick_x) / stick_width) * (2.0 * math.pi)) - (quadrant * (math.pi/2.0))
polar_x = round(hypotenuse * math.cos(theta))
polar_y = round(math.sqrt(hypotenuse**2 - polar_x**2))
#print(stick_x,stick_y)
if quadrant == 0:
im_stick.putpixel((stick_x,stick_y),image.getpixel((200+polar_x,199-polar_y)))
elif quadrant == 1:
im_stick.putpixel((stick_x,stick_y),image.getpixel((199-polar_y,199-polar_x)))
elif quadrant == 2:
im_stick.putpixel((stick_x,stick_y),image.getpixel((199-polar_x,200+polar_y)))
elif quadrant ==3:
im_stick.putpixel((stick_x,stick_y),image.getpixel((200+polar_y,200+polar_x)))
im_stick.show()
im_stick.save("%s\\%s_done.jpg" % (image_path, image_title), quality=100)
im_stick.close()
image.close()
if __name__ == '__main__':
main()

You know what? If you’re interested in programming, you’ll work it out, or you can ask. If you’d like to package it into an app and give me a copy, that would be just peachy. So, having got to grips with some of the rounding errors inherent in the ‘extremes’ of trigonometry, I had a quick play with the results to see how they looked. You may notice, my biggest problems now are:

- How do you get the turning speed right?
- How can you do it without holding the whole thing at arms length and hoping you don’t move?
- The image gets a bit overexposed in the centre.

That aside, here are the less than perfect results, but I don’t care because maths is fun! 😉

The original

The 200 pixel high image on the pixel stick

Glorious!

There is a definite resemblance between the original image and the end result (though I’ve spun round in the wrong direction, so forgive me that). As you can see, limitations on centring and speed. All I’ll say is, this was not my first attempt. So, since I had a few attempts, you have to sit through the second image as well.

150 Years Original

Tadaaaaaaa

The end result, or as close as I got to it

It’s getting dark in the evenings again now – almost time for the next Pixel Stick project…