View Full Version : Help Beginner (Graphics with Ruby)
Akaii
August 2nd, 2005, 08:24 AM
Ruby seems like great fun to try out, so I decided to try and use it for some class projects I need to submit. I can't seem to find any built-in classes for Drawing though. Can anyone refer me to a resource I can use? Something similar to Java's.swing classes, and something I can use for HTML?
bluetechnx
August 2nd, 2005, 02:15 PM
There are many GUI toolkits available for Ruby. Bundled with the standard Ruby distribution is TK. You could use it for drawing with a mouse or making windows and widgets.
Other widely used GUI toolkits are GTK and WxWindows. GTK seems very swing-like in its event system, for example you write the following code to create a button and connect it to some event (like an ActionEvent in Java):
button = Gtk::Button.new("Open")
button.signal_connect("clicked") { ...open some file or object... }
Your question about HTML is a little vague...do you want to output html? view it in a window or textarea or what? I believe GTK has some text widgets that could display html.
Akaii
August 2nd, 2005, 09:19 PM
Thanks for the help.
Apologies if my descriptions are somewhat vague. I don't have as much experience with scripting languages and web applications as I'd like. I was hoping that there'd be some way to embed a canvas in an HTML doc, which takes in paramaters and draws something out based on those parameters prior to sending the document to the web browser.
Let's say, a database of X, Y coordinates...and depending on the request made by the client, the app retrieves a certain set, prints them on a canvas, embeds it in HTML, and sends it to the client. That's roughly what I'm trying to do.
bluetechnx
August 3rd, 2005, 01:19 AM
Well. Hypothetically speaking your application sounds like you want to highlight points on a canvas (regions of interest, ROI) based upon some values set by the user. I'm sorta thinkin of like a street map and a user enters in a zipcode and all the hospital locations get a red dot on them or something....
I am not really aware of any Ruby library to embed a canvas widget into an HTML page. I know using Java and applets you could make a Canvas object and embed in it the page and do your database queries and show your (X,Y) points....but I'm not aware of a mature easy to use library to do the equivelant in Ruby.
There is an library called "RubyWebDialogs" which behaves *alot* like Java applets, but at a glance it does not have a canvas widget, it might though.
As an alternative you could use Ruby on Rails for your webpage and database quering, and use RMagic to create images to show the X,Y locations from the database. So, instead of using a canvas, you could make a static image instead....just a thought.
Akaii
August 3rd, 2005, 09:17 AM
RMagic sounds like what I'm looking for... Thanks.
Is there any possible way to make the static image interactive though? Clickable?
rob
August 3rd, 2005, 12:40 PM
Is there any possible way to make the static image interactive though? Clickable?
I don't think so, but you could img src it and then do an image map, making different parts of it clickable.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.