The Many Faces of SDL

Wow! I just checked in with the SDL languages page. It seems there are
bindings for 19 languages. I haven’t even heard of some of the languages
listed, but that is pretty amazing.

I’d love to get a little taste of all the different languages and how
they use SDL. Just as something simple I thought it would be neat if
people submitted small programs that do the same thing with each
binding. Please, not a contest, just something simple to see and learn from.

On the chance this sounds like a good idea, I thought I’d kick it off
with a simple entry for python (using the pygame library). This is just
a simple script that draws random rectangles until the user quits or
presses a key. I’d love to see the equivalent in the other 20 language
bindings for SDL!

Does this make SDL the most “completely binded” C library in existence?
Aside from libc, I wouldn’t think there’d be many other contenders.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: rboxes.py
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021209/9b4541ae/attachment.asc

Pete Shinners writes:

On the chance this sounds like a good idea, I thought I’d kick it off
with a simple entry for python (using the pygame library). This is
just a simple script that draws random rectangles until the user quits
or presses a key. I’d love to see the equivalent in the other 20
language bindings for SDL!
Here’s the equivalent in pure RUDL (ruby binding):----
require ‘RUDL’

alias r rand

def random_rect size
x, y = r(size[0]), r(size[1])
[x, y, r(size[0] - x), r(size[1] - y)]
end

def main
stop_events = [RUDL::KeyDownEvent, RUDL::QuitEvent]
size = [640, 480]
win = RUDL::DisplaySurface.new size

catch(:enough) {
loop {
while event = RUDL::EventQueue.poll
throw :enough if stop_events.include? event.type
end

  win.fill [r(255), r(255), r(255)], random_rect(size)
  win.flip
}

}
end

main if FILE == $0

Here’s another one using my application class (see attached file):

require ‘slimb/rudl/application’

class RandomRectApp < RUDL::GenericApplication
def initialize size
super “Random Rect in RUDL”, size[0], size[1]
end

def random_rect
x, y = rand(@width), rand(@height)
[x, y, rand(@width - x), rand(@height - y)]
end

def random_color
[rand(255), rand(255), rand(255)]
end

def render
@screen.fill random_color, random_rect
end

def on_keypress key
quit
end
end

if FILE == $0
size = [640, 480]
RandomRectApp.new(size).run
end

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed…
Name: application.rb
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021210/5b516564/attachment.txt
-------------- next part --------------

– Ed