2

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!! :)

aayush shrestha
  • 1,858
  • 2
  • 17
  • 33

1 Answers1

2

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.

SimonMayer
  • 4,719
  • 4
  • 33
  • 45
  • Thanks SimonMayer for answering the question. This gave me a little headstart on things. but it still hasn't solved the problem. I researched and found that shoes also has line drawing function, which i can use. But I also need to plot at individual pixels. Can I do it in shoes? If not, any other ways to do it?? Thanks! :) – aayush shrestha Feb 24 '12 at 02:17
  • There are some Shoes tutorials at http://shoesrb.com/tutorials - specifically there is an example on the first page, called "Scribble", which demonstrates drawing lines. You may also want to check out the manual: http://shoesrb.com/manual/Art.html – SimonMayer Feb 24 '12 at 02:21