Running with Shoes – Shapely

This tutorial describes some of the basic graphic capabilities of the Shoes mini-GUI toolkit.

Arrow
The Shoes mini-GUI toolkit has a arrow method that draws a simple arrow pointing to the right. You can pass in the location of the tip of the arrow in the form of xy coordinates. The arrow method takes a third parameter to indicate the size.

[source:ruby]
# arrow x, y, size
arrow 100, 100, 50
arrow 100, 100, 100
[/source]

Star
In addition to arrows, you can draw stars with the aptly named star method. Like most of the methods that draw method accepts xy coordinates for the position of the star. The location given as xy coordinates are to the left side of the star. In addition to the location, the star method also accepts two additional and optional integers, one for the number of sides and the other to indicate the size of the star.

[source:ruby]
# star x, y, sides, size
star 0, 0, 31, 100
[/source]

As of this writing, the star method does not draw nice looking star with even number of shapes. You can only draw a star with odd number of sides. A star with 3 sides draws a triangle.

Oval
The oval function can be used to draw circle or oval shapes. The oval method accepts an a pair of integers to indicate the shape’s x, y location. The location given is to the top left side of the oval. The oval method also accepts a third option to indicate the diameter of the circle.

[source:ruby]
oval x, y, dimeter
oval 10, 20, 30, 40
[/source]

To draw oval shapes the oval function accepts a fourth argument. When the fourth argument is given, the third argument indicates the width of the oval and the fourth argument indicates the height.

Rect
As you can imagine, you can use the rect method to draw rectangles. The rect method accepts two arguments to indicate the x, y location of the top left side corner of the rectangle. The rect method also required two additional arguments to specify the width and height.

[source:ruby]
# rect x, y, width, height
rect 0, 0, 20, 20
[/source]

There are more Shoes GUI tutorials and code samples here.

Technorati Tags: , , , , ,