views:

102

answers:

3

I'm trying to plot points from a very large array into an image using Ruby. Such that the array items are represented by a point or dot of the appropriate colour, and the dots together form the shape. Since the dots are from the array they are not random in colour or location to each other, so I'm confused how to begin.

I want to eventually make the shape of a spiral galaxy, but just consider the opening question above. Later this can also get complicated because the middle will have more dots that the outer layers, but again that doesn't matter. I just want to know how to first start using my array items to make an ordered image based on the colours of the array items.

With that initial image, I can then split up the image into tiles which each tile is clickable representing an area of points, eventually allowing me to use the first process again and again to make a quadrant and then for a solar system etc.

I'm unaware of how to represent the initial image to being with.

I'm using Ruby and the Rmagick library. If there is another package to use or even another Linux based program (cmd or gui) that can help make this initial image, that would be a big help.

Thanks

A: 

If you have already managed to get RMagick up and running, I would suggest you utilise it's SVG capabilities. This snippet will help.

So now you have a canvas in 2D which you'll create at a given size.

Your array must, in some form or other, contain a geometric representation of where the dots must go. You'll need a conversion function to scale from your representation (which I am assuming is a coordinate system representative of the real universe and probably 3D) into a something two dimensional from a given viewpoint. If you already have 2D plot coordinates, then a simple scaling will suffice.

You should find that most 2D graphics libraries provide scaling functions built in. In many cases you can work in your real coordinate system and the graphics engine can be made to scale down accordingly.

wentbackward
A: 

Thanks. The snippet noted ellipse as a method, which is probably as close as I'm going to get out of the box to a 2D galaxy. So the galaxy could easily be a circular core, with multiple ellipse rings, then some curves off the last ellipse. Sweet.

Coordinate systems are one basis of order, but for flex I don't need a specific coordinate, only the order, like a chain of DNA. But the coords I have will map out okay.

But say I wanted a /Pictures directory made to resemble a giraffe. I don't have the coordinates of the giraffe, but if I drew one, I'd like to shape it with the pictures that I have, in the order of the directory list, along the trajectory of the image lines.

I'll play around a bit.

energyblogwalter
+1  A: 

trying to delete my comment... just let me delete it stackoverflow

energyblogwalter