Search code examples
rubycairoshoes

Cairo and Shoes in Ruby


How do I use Cairo ta draw on a shoes window?

I am trying to start a school project for Computer Graphics. Can anybody post a simple code that draws a circle on a shoes window? I'd be very grateful. I have been searching for quite a while now... I've reached nowhere yet. so, please help me!! :)


Solution

  • I'm not sure how you would use Cairo in Ruby. It's not my area of expertise; however drawing circles in Shoes is not difficult at all. The following example allows circles to be created from mouse clicking and dragging.

    Shoes.app do
        ox,oy = nil,nil
        click{|button, x, y| # on click, set the original x and y position
            if button == 1
                ox = x
                oy = y
            end
        }
        release{|button, x, y| #on mouse release, draw the circle
            if button == 1
                oval(
                    :left => [ox, x].min, # furthest left point
                    :top => [oy, y].min, # furthest top point
                    :radius => ((ox-x).abs + (oy-y).abs) / 2 # the average of the positive difference between original and final x and y points
                )
            end
        }
    end
    

    Obviously, depending on your specific requirements, you will need to decide whether it is good enough.

    In my experience, Shoes is a decent platform for making a broad range of low to medium power apps. However, if you're trying to build something substantial, like a graphics package, there are probably better solutions.