File: randrect.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 (40 lines) | stat: -rw-r--r-- 766 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
36
37
38
39
40
# SDL random rect sample
# original code by adas@geocities.co.jp written by C
# auther TAMURA Kenichi <sgs02516@nifty.com>
#
require 'sdl'

src_w = 640
src_h = 480
src_d = 16

dst_w = 0
dst_h = 0

MAX = 1000
RECTSIZE = 400

SDL.init SDL::INIT_VIDEO
screen = SDL::setVideoMode src_w,src_h,src_d, SDL::SWSURFACE|SDL::ANYFORMAT

srand

(1 .. MAX).each do |i|
  color = screen.mapRGB rand(256),rand(256),rand(256)
  dst_w = rand(RECTSIZE) + 1
  dst_h = rand(RECTSIZE) + 1
  screen.fillRect rand(src_w-dst_w), rand(src_h-dst_h), dst_w, dst_h, color
  screen.updateRect 0,0,0,0

  while event = SDL::Event.poll
    case event
    when SDL::Event::Quit
      exit
    when SDL::Event::KeyDown
      exit if event.sym == SDL::Key::ESCAPE
    end
  end

  SDL::Key.scan
end