File: ellipses.rb

package info (click to toggle)
libsdl-ruby 1.1.0-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,320 kB
  • ctags: 1,157
  • sloc: ansic: 4,375; ruby: 1,837; makefile: 54
file content (35 lines) | stat: -rw-r--r-- 796 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# SDL random ellipses
# Author: Wayne Conrad <wconrad@yagni.com>

require 'sdl'

def show(function)
  event = SDL::Event.new
  screen = SDL::setVideoMode(640, 480, 16, SDL::SWSURFACE|SDL::ANYFORMAT)
  loop do
    color = screen.mapRGB(rand(256),rand(256),rand(256))
    x = rand(screen.w)
    y = rand(screen.h)
    xr = rand(80)
    yr = rand(80)
    eval("screen.#{function}(x, y, xr, yr, color)")
    if event.poll != 0 then
      case event.type
      when SDL::Event::QUIT
        exit
      when SDL::Event::MOUSEBUTTONDOWN
        break
      when SDL::Event::KEYDOWN
        exit if event.keySym == SDL::Key::ESCAPE
        break
      end
    end
    SDL::Key.scan
    screen.updateRect(0, 0, 0, 0)
  end
end

srand
SDL.init SDL::INIT_VIDEO
show("drawEllipse")
show("drawFilledEllipse")