Shapes and Colors for Ruby

May 6th 01:10
by why

Looks like the infectious hacking spirits are really sinking their teeths in!! Nathan W started cobbling together a NodeBox-alike for Ruby using Cairo and it’s really coming along.

Good use of blocks to start shapes, Nathan. You start a shape with shape(x, y) and attach a block that lets you further the shape with the line, jump and curve methods. I really like how the block houses the complete shape outline.

So, to get this up and running you need GTK2, Cairo and the Ruby bindings for both. On Windows, you can get the Ruby-Gnome2 installer, which includes all of that. Good show, Nathan.

9 comments

Peter

said on May 6th 05:25

When will something like this appear inside HH? :)

Kiddo

said on May 6th 08:01

it would be cool if the brush fill colors were words like GREEN and RED and we should be able to do GREEN+BLUE and pass that to the brush.fill command.

Nathan

said on May 6th 15:53

Peter: Soon, hopefully. I tried to structure it so that it would be easily embeddable in HH.

Kiddo: I just committed a version where you can set brush colors by name. They aren’t addable, because I wanted to have them settable with symbols.

  brush.fill, brush.stroke = :navajo_white, :red

misuba

said on May 6th 16:45

Now can we combine this with LittleCoder somehow?

nertzy

said on May 6th 18:41

The site talks about some “Why the lucy stiff”! Is this your female counterpart?

Klondike

said on May 7th 08:45

Nathan, perhaps you could define the + method on symbols, to control what mixing certain colors with others would produce. Could be neat.

Nathan

said on May 8th 04:06

Heehee… :red + :green #=> :yellow. Yeah, that’s a good idea.

weepy

said on May 9th 03:46

Nathan, if you could do something like the color operators in Sass that would be great

Vagabond

said on May 9th 23:43

Sorry for the long snippet, but adding symbols as colors kinda inspired me a little:



module ColorSymbols
  COLORS = {
    :red => [255, 0, 0],
    :green => [0, 255, 0],
    :blue => [0, 0, 255],
    :yellow => [127, 127, 0]
  }

  # stupid lack of non-recursive flatten...
  REVCOLORS = Hash[*(COLORS.to_a.map{|x| x.reverse}.
        inject([]){|sum,n| n.kind_of?(Array) ? sum + n : sum << n})]

  def +(other)
    color = [COLORS[self], COLORS[other]].transpose.map{|x| (x[0]+x[1])/2}
    return REVCOLORS[color] ? REVCOLORS[color] : color
  end

end

class Symbol
  include ColorSymbols
end

Outputs:

:red + :green => :yellow
:red + :yellow => [191, 63, 0]

Comments are closed for this entry.