File: ellipses.rb

package info (click to toggle)
ruby-sdl 2.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,344 kB
  • ctags: 4,200
  • sloc: cpp: 7,598; ansic: 4,475; ruby: 2,258; sh: 102; makefile: 97
file content (39 lines) | stat: -rw-r--r-- 804 bytes parent folder | download | duplicates (5)
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
36
37
38
39
# SDL random ellipses
# Author: Wayne Conrad <wconrad@yagni.com>

require 'sdl'

def show(fill)
  screen = SDL::Screen.open(640, 480, 16, SDL::SWSURFACE)
  format = screen.format
  loop do
    color = format.map_rgb(rand(256),rand(256),rand(256))
    x = rand(screen.w)
    y = rand(screen.h)
    xr = rand(80)
    yr = rand(80)
    screen.draw_ellipse(x, y, xr, yr, color, fill)
    while event = SDL::Event.poll
      case event
      when SDL::Event::Quit
        exit
      when SDL::Event::KeyDown
        if event.sym == SDL::Key::ESCAPE
          exit
        else
          return
        end
      when SDL::Event::MouseButtonDown
        return
      end
    end
    screen.updateRect(0, 0, 0, 0)
    sleep 0.05
  end
  screen.destroy
end

srand
SDL.init SDL::INIT_VIDEO
show(false)
show(true)