Archive

Category Archives for "Pixel Stick"

Going Polar

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

Symmetrical-ish

Simplified conversion of a circular picture into a rectangular picture

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?

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! 😉

Small yellow flower

The original

Flower image distorted for pixel stick

The 200 pixel high image on the pixel stick

 

Flower drawn with rotating 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 of Portobello and Golborne Market

150 Years Original

Pixel Stick image of Portobello 150 years

Tadaaaaaaa

Pixel Stick Portobello rotated image

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…

What am I thinking?

If you see me with a slightly glazed look on my face, there’s a fair chance my brain has gone off to do some maths.  Nothing super complicated, mostly stuff with triangles, I like triangles, but today it’s circles.

I got a new toy, a pixel stick to be exact.  A pixel stick is a 6 foot long bar of 200 full colour range LEDs, attached to a handle that allows you to spin the stick if you want.  You upload an image to it and then, while you take a long exposure, plays back the image one row at a time, ‘printing’ the picture onto the camera sensor as it goes.  Of course, once I’ve played with something for 10 minutes, I have to try to work out what else I can do with it, and this was no exception.

pixel stick image of hokusai behind a car

Hokusai wave breaking over a car

Here is one of my first attempts, using an example image that came with the stick (patience is not my strongest characteristic).  So, what else can you do?  Well, as you’re probably aware, I like to do a bit of maths mixed in with the photography and, as I was lying in bed with nothing to do, I was running sine waves and things through my head.  What happens if you rotate a sine wave around a central axis?  As it turns out, you get a circle.  And if you have four sine waves at regular intervals?

Diagram of how rotating a sine wave yields circles

Circles from Sine waves

Surprisingly enough, you get a circle in each quadrant of the overall spinning circle, each with a diameter half of the original circle.  I’ve tried to illustrate it to the left there.  At the beginning, the sine wave moves quickly away from the centre, but the centre of the stick moves slowly, so it doesn’t make huge changes.  As it gets to the edge, the rate of change of the distance from the centre is slower, but the outer edge of the stick moves quickly.  The net effect is that, for each cycle of the wave, two circles are drawn in the ‘right’ quadrant of the pixel stick.  So, adding three more staggered sine waves will give 3 more circles in the other three quadrants.  If you ever needed an excuse to love trigonometry… then you’re probably not as sad as I am.

Four staggered sine waves in rainbow colours

Rainbow sine waves

You end up with an image looking something like this, the rainbow is obviously in there because everything looks prettier in rainbow colours.  I’m not going to be able to surprise you with how it comes out, because you’ve already skimmed to the pictures.  I wasn’t really aiming to get four perfect circles intertwined, I wanted to see what it looked like repeating over and over.  Here’s the end result, I hope you like it.

Pixel stick circles on Brentford waterfront

Circular sine waves