[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

DRAW 1280, 1024

benjohn

9/9/2006 7:39:00 AM

20 years ago, the subject line would have drawn me a line across one
of my screen's diagonals. Ruby is awesomely more powerful than BBC
BASIC, but why no trivial graphics support?

My two requirements are that it should be really easy to draw, and it
should be possible to do so interactively (from irb).

I've looked unsuccessfully in the past, but if this is a solved
problem then I'd really like to know. Otherwise, does anyone have a
suggestion of where to start?

Personally, I'm on a Mac. If there is a solution for my world, that
would do for me. Something global would rock though.

Hope you have a lovely weekend,
Benjohn



30 Answers

Paul Lutus

9/9/2006 8:19:00 AM

0

Benjohn Barnes wrote:

> 20 years ago, the subject line would have drawn me a line across one
> of my screen's diagonals. Ruby is awesomely more powerful than BBC
> BASIC, but why no trivial graphics support?

Because there is no trivial way to make graphics facilities
platform-independent. You may notice that Ruby has native libraries for
graphic interfaces, but these are also not platform-independent. Through
those graphic interfaces, you can make drawings, but you then cannot run
the program anywhere but on the original platform (with some exceptions).

> My two requirements are that it should be really easy to draw, and it
> should be possible to do so interactively (from irb).

Well, "irb" has a special purpose, and being a user interface for a drawing
program isn't the purpose.

> I've looked unsuccessfully in the past, but if this is a solved
> problem then I'd really like to know. Otherwise, does anyone have a
> suggestion of where to start?
>
> Personally, I'm on a Mac. If there is a solution for my world, that
> would do for me. Something global would rock though.

Global, there's the rub. I am sure there are libraries on the Mac that allow
graphic interfaces to Ruby programs, but they aren't likely to be portable.

--
Paul Lutus
http://www.ara...

benjohn

9/9/2006 8:41:00 AM

0


On 9 Sep 2006, at 09:20, Paul Lutus wrote:

> Benjohn Barnes wrote:
>
>> 20 years ago, the subject line would have drawn me a line across one
>> of my screen's diagonals. Ruby is awesomely more powerful than BBC
>> BASIC, but why no trivial graphics support?
>
> Because there is no trivial way to make graphics facilities
> platform-independent. You may notice that Ruby has native libraries
> for
> graphic interfaces, but these are also not platform-independent.
> Through
> those graphic interfaces, you can make drawings, but you then
> cannot run
> the program anywhere but on the original platform (with some
> exceptions).

It may not be trivial, but it's hardly difficult. There must be
dozens of Ruby modules that have varying implementation by platform
(sockets, for example)? Ruby itself pulls the feat of quite nicely
too. Note that I'm not talking about taking full control of graphics
hardware and exploiting all features. It's just really basic drawing
support that would be good.

>> My two requirements are that it should be really easy to draw, and it
>> should be possible to do so interactively (from irb).
>
> Well, "irb" has a special purpose, and being a user interface for a
> drawing
> program isn't the purpose.

I'm not suggesting that irb needs changing. I'm suggesting that the
design of the graphics API I'm hoping for should be "irb friendly",
which I believe it will be if well designed. Thus, using irb, I
should be able to issue a commands and see the result. I shouldn't
have to create contexts and windows, program up call backs, cache my
drawing commands somewhere ready for a re-paint and string the lot
together.

>> I've looked unsuccessfully in the past, but if this is a solved
>> problem then I'd really like to know. Otherwise, does anyone have a
>> suggestion of where to start?
>>
>> Personally, I'm on a Mac. If there is a solution for my world, that
>> would do for me. Something global would rock though.
>
> Global, there's the rub. I am sure there are libraries on the Mac
> that allow
> graphic interfaces to Ruby programs, but they aren't likely to be
> portable.

I've not even found something that merely works on the Mac, yet alone
globally!

I apologise if I sound exasperated Paul, and thank you for replying.
It's not like I'm asking for a flying car here though: I just want my
bicycle back.



Chad Perrin

9/9/2006 9:17:00 AM

0

On Sat, Sep 09, 2006 at 04:39:04PM +0900, Benjohn Barnes wrote:
> 20 years ago, the subject line would have drawn me a line across one
> of my screen's diagonals. Ruby is awesomely more powerful than BBC
> BASIC, but why no trivial graphics support?
>
> My two requirements are that it should be really easy to draw, and it
> should be possible to do so interactively (from irb).
>
> I've looked unsuccessfully in the past, but if this is a solved
> problem then I'd really like to know. Otherwise, does anyone have a
> suggestion of where to start?
>
> Personally, I'm on a Mac. If there is a solution for my world, that
> would do for me. Something global would rock though.

If you're willing to try a different language, there's always Logo. In
particular, I like UCBLogo (which, unlike other Logo versions,
implements macros along with the rest of the Lispishness of the
language). It has a very friendly functional syntax, has an excellent
lineup of native graphics procedures (aka "functions), and is the
example language used for an excellent trilogy of computer science books
that are available free, online.

Since this is a bit off-topic for this venue, I'll shut up now, but let
me know if you want more information (links to resources, et cetera).

As for Ruby . . . I don't know of any capabilities such as those you
suggest, and I don't see them arising any time soon. I could be
mistaken, however.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
unix virus: If you're using a unixlike OS, please forward
this to 20 others and erase your system partition.

Martin DeMello

9/9/2006 9:26:00 AM

0

On 9/9/06, Benjohn Barnes <benjohn@fysh.org> wrote:
> 20 years ago, the subject line would have drawn me a line across one
> of my screen's diagonals. Ruby is awesomely more powerful than BBC
> BASIC, but why no trivial graphics support?
>
> My two requirements are that it should be really easy to draw, and it
> should be possible to do so interactively (from irb).

You could build something atop Rubygame [ http://rubygame... ]
fairly easily. In fact you could probably write a BBC graphics
emulator, though the cursor-based thing would seem slightly odd in
this day and age :) A QBasic graphics emulator otoh might be a
worthwhile effort - IIRC it was pretty well thought-out and simple to
use. Here's a quick example using plain Rubygame:

irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'rubygame'
=> false
irb(main):003:0> Rubygame.init
=> nil
irb(main):004:0> screen = Rubygame::Screen.set_mode([640, 480])
=> #<Rubygame::Screen:0xb78ebc20>
irb(main):005:0> red = [255, 0, 0]
=> [255, 0, 0]
irb(main):006:0> Rubygame::Draw.line(screen, [0, 0], [639, 479], red)
=> #<Rubygame::Screen:0xb78ebc20>
irb(main):007:0> screen.update
=> #<Rubygame::Screen:0xb78ebc20>

The simplest way would be to have a class that automatically
initialized a screen and held it as an instance variable, and a set of
methods that wrapped the methods in Rubygame::Draw but passed in the
default screen and remembered the last colour that was used in case no
colour was supplied. For example
-------------------------------------------------------------------------------------------
require 'rubygems'
require 'rubygame'

class Sketchpad
def initialize(x,y)
@screen = Rubygame::Screen.set_mode([x, y])
@color = [255, 255, 255] #white
Thread.new {
loop {
@screen.update
sleep 0.01
}
}
end

def line(x1, y1, x2, y2, color=@color)
@color = color
Rubygame::Draw.line(@screen, [x1, y1], [x2, y2], @color)
@screen.update
end
end
-------------------------------------------------------------------------------------------
irb(main):001:0> require 'sketchpad.rb'
=> true
irb(main):002:0> s = Sketchpad.new(640, 480)
=> #<Sketchpad:0xb791b808 @color=[255, 255, 255],
@screen=#<Rubygame::Screen:0xb791b7cc>>
irb(main):003:0> s.line(0, 0, 639, 479)
=> #<Rubygame::Screen:0xb791b7cc>
irb(main):004:0> s.line(0, 479, 639, 0, [0, 0, 255])
=> #<Rubygame::Screen:0xb791b7cc>

martin

Martin DeMello

9/9/2006 9:37:00 AM

0

On 9/9/06, Benjohn Barnes <benjohn@fysh.org> wrote:
>
> I'm not suggesting that irb needs changing. I'm suggesting that the
> design of the graphics API I'm hoping for should be "irb friendly",
> which I believe it will be if well designed. Thus, using irb, I
> should be able to issue a commands and see the result. I shouldn't
> have to create contexts and windows, program up call backs, cache my
> drawing commands somewhere ready for a re-paint and string the lot
> together.

There's no getting around the "have to create contexts and windows"
part - base ruby has absolutely no built-in idea of a graphics
context. However, you can do this automatically as follows: to the
bottom of sketchpad.rb add

@sketchpad = Sketchpad.new(640, 480)

def line(*args)
@sketchpad.line(*args)
end

(that is, outside the class definition)

now 'require sketchpad.rb' will execute the lines, create a @sketchpad
object accessible from within irb, and let you call line as a function
straight from the prompt. As a final touch, you can automatically
require sketchpad.rb from your irbrc.

Look also at the Delegator and Forwardable modules for some ways of
automating the method wrapping.

martin

Chad Perrin

9/9/2006 10:23:00 AM

0

On Sat, Sep 09, 2006 at 06:46:51PM +0900, Robert Dober wrote:
>
> Chad
> maybe you remember the post where I was discarding D and you kind of made me
> think about it twice. This is a good time to come back [ I consider this
> group flexible enough not to be bothered by slighly off topic posts but feel
> free to tell me if I am wrong ] to you on this point.
> I do not regret at all looking at D a second time and it indeed seems a very
> nice thing to have in your toolbox!!!.
> So why not toss in the links for UCBLogo?
> I feel it might be of interest for more folks than just OP and myself.
> If you feel differently about it could you reply to me offlist?
> Thx in advance

Good point(s). I'll post links here, at least:

central UCBLogo resources page:
http://www.cs.berkeley.edu/~bh...

Computer Science Logo Style
Volume 1: Symbolic Computing
http://www.cs.berkeley.edu/~bh/v1...

Computer Science Logo Style
Volume 2: Advanced Techniques
http://www.cs.berkeley.edu/~bh/v2...

Computer Science Logo Style
Volume 3: Beyond Programming
http://www.cs.berkeley.edu/~bh/v3...

At least some Linux distributions (Debian included) provide UCBLogo
packages in their software archives. I was delighted to find that I
could install UCBLogo on my Debian systems by typing "apt-get install
ucblogo" (without the quotes) into a root shell. Quite convenient.

Logo has been called the "Lisp without parentheses", and that's pretty
much what it is. Most implementations have been somewhat neutered in
the creators' zeal for producing a language implementation that is
friendly to young students, but UCBLogo is not of that ilk -- it goes so
far as to include support for Lisp macros (though I haven't personally
explored their use enough to be able to make a determination about how
well they're supported, the syntax and use seems quite similar to that
of ANSI Common Lisp).

It's an open source distribution of Logo created by a Berkeley
professor, Bryan Harvey, who is also the author of the above-mentioned
university computer science textbooks that make use of UCBLogo as the
example language. I've found the books to be well-written (so far -- I
have been often and thoroughly distracted by the demands of other
languages in my life, alas), and the language absurdly easy to learn.
It has been the single biggest factor in my growing appreciation for
arithmetic prefix notation, and functional syntax in general, so far.

Suddenly, I'm considering creating a mailing list . . . damn. Like I
don't have enough on my plate already.

--
CCD CopyWrite Chad Perrin [ http://ccd.ap... ]
"Real ugliness is not harsh-looking syntax, but having to
build programs out of the wrong concepts." - Paul Graham

David Vallner

9/9/2006 10:53:00 AM

0

Benjohn Barnes wrote:
> Personally, I'm on a Mac. If there is a solution for my world, that
> would do for me. Something global would rock though.

The best I can think of in portability is using wxWidgets / FOX / Gtk to
draw inside a 2D buffer in a window / GUI widget. OpenGL or SDL to draw
full-screen. I don't think it's trivially easy to doodle over someone's
GUI though - though OpenGL or SDL might be able to draw on the overlay
too. Lookup bindings to those libraries, I'm fairly sure that they're
both available, and reasonably cross-platform.

David Vallner

Martin DeMello

9/9/2006 11:05:00 AM

0

On 9/9/06, David Vallner <david@vallner.net> wrote:
> Benjohn Barnes wrote:
> > Personally, I'm on a Mac. If there is a solution for my world, that
> > would do for me. Something global would rock though.
>
> The best I can think of in portability is using wxWidgets / FOX / Gtk to
> draw inside a 2D buffer in a window / GUI widget.

I think all the GUI toolkits insist on running their own mainloop,
which plays badly with IRB

> OpenGL or SDL to draw full-screen.

You can run OpenGL or SDL inside their own windows. I think this is
the way to go.

> I don't think it's trivially easy to doodle over someone's
> GUI though - though OpenGL or SDL might be able to draw on the overlay
> too. Lookup bindings to those libraries, I'm fairly sure that they're
> both available, and reasonably cross-platform.

Doodling over a GUI is of limited use anyway. Simply having a canvas
you can interactively draw on from IRB is a neat thing. It was one of
the features I'd planned for FXIrb, but I don't have the time to
maintain that these days :(

martin

David Vallner

9/9/2006 11:15:00 AM

0

Martin DeMello wrote:
> I think all the GUI toolkits insist on running their own mainloop,
> which plays badly with IRB
>

Spawn off inna thread, then jump through event posting hoops?

Just ranting, SDL would be prolly both easier to get to work and with a
richer API for drawing.

Paul Lutus

9/9/2006 3:43:00 PM

0

Benjohn Barnes wrote:

> On 9 Sep 2006, at 09:20, Paul Lutus wrote:
>
>> Benjohn Barnes wrote:
>>
>>> 20 years ago, the subject line would have drawn me a line across one
>>> of my screen's diagonals. Ruby is awesomely more powerful than BBC
>>> BASIC, but why no trivial graphics support?
>>
>> Because there is no trivial way to make graphics facilities
>> platform-independent. You may notice that Ruby has native libraries
>> for
>> graphic interfaces, but these are also not platform-independent.
>> Through
>> those graphic interfaces, you can make drawings, but you then
>> cannot run
>> the program anywhere but on the original platform (with some
>> exceptions).
>
> It may not be trivial, but it's hardly difficult. There must be
> dozens of Ruby modules that have varying implementation by platform
> (sockets, for example)?

Yes, but sockets don't compare well with a graphic interface. Sockets talk
to the network, which all environments want to do in the same way. Graphic
interfaces talk to the hardware and the OS, which have less in common with
each other than sockets do.

> Ruby itself pulls the feat of quite nicely
> too. Note that I'm not talking about taking full control of graphics
> hardware and exploiting all features. It's just really basic drawing
> support that would be good.

And it exists, and you can easily write a drawing program, but it won't be
particularly platform-portable.

>>> My two requirements are that it should be really easy to draw, and it
>>> should be possible to do so interactively (from irb).
>>
>> Well, "irb" has a special purpose, and being a user interface for a
>> drawing
>> program isn't the purpose.
>
> I'm not suggesting that irb needs changing. I'm suggesting that the
> design of the graphics API I'm hoping for should be "irb friendly",
> which I believe it will be if well designed.

I gather that you want is user friendliness, and you have hit upon irb's
friendliness as an example for immediacy of results. You appear to want
your user to be able to enter instructions interactively and see the
results drawn. For this, "eval" would do nicely, better than irb, because
the latter has a rather specialized purpose. But this doesn't address the
more important issue of graphic interface.

> Thus, using irb, I
> should be able to issue a commands and see the result. I shouldn't
> have to create contexts and windows, program up call backs, cache my
> drawing commands somewhere ready for a re-paint and string the lot
> together.

But yes, you would have to do that, at least once. You would have to so that
because, apart from Logo, there are few ready-built graphic facilities such
as you are describing. You would have to write the program, then you would
have to integrate a graphic interface. And in the worst case, you would
have to perform the second step for each platform of interest.

> I've not even found something that merely works on the Mac, yet alone
> globally!

This addresses the state of the art. A suitable "bicycle" analog is Ruby as
we find it today, which is quite remarkable in and of itself. But from my
perspective as a computer programmer in 2006, you are actually asking for a
Porsche.

> I apologise if I sound exasperated Paul, and thank you for replying.
> It's not like I'm asking for a flying car here though: I just want my
> bicycle back.

This is why computer programming hasn't withered away as a profession, even
though some might argue that it should.

--
Paul Lutus
http://www.ara...