msgbartop
Code Musings and Such
msgbarbottom

12 Nov 08 Ruby Line / Curve…Thing

Remember these?

During a brief period in elementary school drawing these things was quite the cool thing to do. I've been messing around with the GD2 module a bit lately and I thought it'd be fun and easy to write a little script to generate one.

It was.

The drawing algorithm

@nodes.times do |i|
    adjustment = i * @node_size
    pen.move_to adjustment, 0
    pen.line_to 0, @size - adjustment
end

Example Usage:

#takes in the output image size and the number of nodes
c = Curve.new 180, 30
c.draw
c.export "test.gif"

Download it!

*Note: If your output size doesn't divide evenly by the number of nodes then the image will actually reduce the size of the output image.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Tags: ,

Leave a Comment