[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Late entry (was Re: [SUMMARY] LSRC Name Picker (#129

Gregory Seidman

7/5/2007 9:21:00 PM

Sorry, I just didn't have enough time to get this done until now. See below
for an explanation of my solution. Quick summary:

- code at http://rubyquiz.com/hosted_solutions/129/grego... (thanks,
James!)
- requires ruby-opengl and RMagick gems
- maintains state in a simple file
- when running, space bar chooses a name or switches back to the idle
screen and the escape key quits (and saves)

On Thu, Jul 05, 2007 at 09:51:11PM +0900, Ruby Quiz wrote:
> Everyone who had my name in their example prize list deserves extra
> credit. I won millions in cash and prizes as I examined the solutions
> this week. I can't wait until the checks start coming in the mail.
>
> I was occasionally beat out by some Yukihiro Matsumoto guy though.
> Weird.

Heh. I was using both names for my testing as well, and they appear in my
included sample list.txt file.

> As usual, there were a lot of great solutions. We had everything from clever
> ASCII art to full GUI applications. There were also a lot of clever ways to
> taunt the attendees before a name is picked.
[...]

I went for gratuitous in my solution, largely because I used it as an
excuse to brush up on my long-languishing OpenGL skills. It depends on the
ruby-opengl gem for 3D rendering and the RMagick gem for dynamically
generated textures. Anyone planning on working with the ruby-opengl
library, especially anyone planning on creating or loading textures from
disk, may find it helpful to look through the framework I set up and the
texture code.

The actual name picking is dead simple, and all it does to maintain state
is to save the list of names, minus those which were chosen, to the same
file it got as input when quitting. The main.rb file should be run and
passed a filename as its only argument. The file should contain the list
from which names will be chosen, one name per line. Note that the list file
must use UTF8 encoding; RMagick can handle UTF8-encoded non-ASCII
characters, though you may need to change the font family in
magick_texture.rb (see below) to get some of the more interesting
characters.


The zip file (see above for URL) includes the following source files:

main.rb
run the program as: ruby main.rb list.txt
render_layer.rb
the base framework for dealing with OpenGL
name_file.rb
the part that actually picks names out of the hat
interpolate.rb
handle simple one-shot and repeating animation
rotate_anim.rb
wrap rendering in an animated rotation
scale_anim.rb
wrap rendering in an animated scaling
magick_texture.rb
dynamically generate an OpenGL texture with RMagick
string_texture.rb
use MagicTexture to generate a string as a texture
letter_ball.rb
render a letter (via StringTexture) texture-mapped onto a sphere;
the code for the sphere and its texture coordinates was modified
and ported from code found at
http://ozviz.wasp.uwa.edu.au/~pbourke/texture_colour/...
reveal_ball_string.rb
uses animations and LetterBall to reveal the chosen name
render_text.rb
render letters with lines (rather than textures or polygons)
lone_star.rb
displays the spinning letters of Lone Star Ruby Conf and uses
RenderText to do so

Also included is a list.txt file, with one accented character to show that
it works. I've only tested this on MacOS X, but I have every reason to
believe that it will work well anywhere as long as ruby-opengl and RMagick
are properly installed.

--Greg