graphics 1.0.0b1 → 1.0.0b4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/History.rdoc +30 -0
- data/Manifest.txt +39 -7
- data/README.rdoc +48 -4
- data/Rakefile +8 -2
- data/examples/boid.rb +9 -18
- data/examples/bounce.rb +15 -23
- data/examples/canvas.rb +75 -0
- data/examples/collision.rb +6 -6
- data/examples/demo.rb +5 -7
- data/examples/editor.rb +12 -9
- data/examples/fluid.rb +2 -3
- data/examples/fluid2.rb +1 -1
- data/examples/{lito2.rb → gol.rb} +0 -0
- data/examples/{zenspider4.rb → gol2.rb} +0 -0
- data/examples/logo.rb +4 -7
- data/examples/maze.rb +136 -0
- data/examples/tank.rb +10 -11
- data/examples/tank2.rb +12 -17
- data/examples/targeting.rb +1 -1
- data/examples/vants.rb +1 -1
- data/examples/walker.rb +3 -12
- data/examples/walker2.rb +197 -0
- data/examples/zombies.rb +31 -35
- data/ext/sdl/extconf.rb +31 -0
- data/ext/sdl/sdl.c +1067 -0
- data/ext/sdl/sge/INSTALL +72 -0
- data/ext/sdl/sge/LICENSE +504 -0
- data/ext/sdl/sge/Makefile +83 -0
- data/ext/sdl/sge/Makefile.conf +63 -0
- data/ext/sdl/sge/README +219 -0
- data/ext/sdl/sge/Todo +7 -0
- data/ext/sdl/sge/WhatsNew +224 -0
- data/ext/sdl/sge/sge.h +31 -0
- data/ext/sdl/sge/sge_blib.cpp +1939 -0
- data/ext/sdl/sge/sge_blib.h +68 -0
- data/ext/sdl/sge/sge_bm_text.cpp +451 -0
- data/ext/sdl/sge/sge_bm_text.h +71 -0
- data/ext/sdl/sge/sge_collision.cpp +388 -0
- data/ext/sdl/sge/sge_collision.h +54 -0
- data/ext/sdl/sge/sge_config.h +6 -0
- data/ext/sdl/sge/sge_internal.h +152 -0
- data/ext/sdl/sge/sge_misc.cpp +92 -0
- data/ext/sdl/sge/sge_misc.h +37 -0
- data/ext/sdl/sge/sge_primitives.cpp +2516 -0
- data/ext/sdl/sge/sge_primitives.h +111 -0
- data/ext/sdl/sge/sge_rotation.cpp +683 -0
- data/ext/sdl/sge/sge_rotation.h +46 -0
- data/ext/sdl/sge/sge_shape.cpp +762 -0
- data/ext/sdl/sge/sge_shape.h +365 -0
- data/ext/sdl/sge/sge_surface.cpp +1090 -0
- data/ext/sdl/sge/sge_surface.h +100 -0
- data/ext/sdl/sge/sge_textpp.cpp +785 -0
- data/ext/sdl/sge/sge_textpp.h +270 -0
- data/ext/sdl/sge/sge_tt_text.cpp +1456 -0
- data/ext/sdl/sge/sge_tt_text.h +114 -0
- data/graphics_setup.sh +26 -0
- data/lib/graphics.rb +1 -1
- data/lib/graphics/body.rb +50 -3
- data/lib/graphics/extensions.rb +13 -7
- data/lib/graphics/simulation.rb +126 -46
- data/test/test_graphics.rb +52 -12
- data/test/test_sdl.rb +1 -0
- metadata +54 -23
- metadata.gz.sig +0 -0
- data/.gemtest +0 -0
- data/examples/lito.rb +0 -108
- data/examples/zenspider1.rb +0 -93
- data/examples/zenspider2.rb +0 -123
- data/examples/zenspider3.rb +0 -104
- data/rubysdl_setup.sh +0 -34
data/examples/zenspider2.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
srand 42
|
4
|
-
|
5
|
-
class Array
|
6
|
-
include Comparable
|
7
|
-
|
8
|
-
alias old_spaceship <=>
|
9
|
-
|
10
|
-
def <=> other
|
11
|
-
x = first <=> other.first
|
12
|
-
x.zero? ? self[1] <=> other[1] : x
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class GameOfLife
|
17
|
-
delta = [-1, 0, 1]
|
18
|
-
same = [0, 0]
|
19
|
-
|
20
|
-
DELTAS = (delta.product(delta) - [same]).sort
|
21
|
-
MIN = { true => 2, false => 3 }
|
22
|
-
|
23
|
-
@@neighbors = Hash.new { |h, k| h[k] = {} }
|
24
|
-
|
25
|
-
attr_accessor :cells
|
26
|
-
attr_accessor :cache
|
27
|
-
|
28
|
-
def initialize
|
29
|
-
self.cells = []
|
30
|
-
end
|
31
|
-
|
32
|
-
def randomize n, m
|
33
|
-
dimensions = n.times.to_a
|
34
|
-
cells.replace dimensions.product(dimensions).sample(m).sort
|
35
|
-
end
|
36
|
-
|
37
|
-
def run max = 1.0 / 0
|
38
|
-
(1..max).each do |n|
|
39
|
-
yield n
|
40
|
-
update
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def update
|
45
|
-
cells.replace considered.select { |(x, y)| alive? x, y }.sort
|
46
|
-
end
|
47
|
-
|
48
|
-
def considered
|
49
|
-
cells.map { |(x, y)| neighbors_for(x, y) }.flatten(1).uniq
|
50
|
-
end
|
51
|
-
|
52
|
-
def binary_search(container, item)
|
53
|
-
return nil if item.nil?
|
54
|
-
low = 0
|
55
|
-
high = container.size - 1
|
56
|
-
while low <= high do
|
57
|
-
mid = (low + high) / 2
|
58
|
-
val = container[mid]
|
59
|
-
if val > item then
|
60
|
-
high = mid - 1
|
61
|
-
elsif val < item then
|
62
|
-
low = mid + 1
|
63
|
-
else
|
64
|
-
return val
|
65
|
-
end
|
66
|
-
end
|
67
|
-
nil
|
68
|
-
end
|
69
|
-
|
70
|
-
def alive? x, y
|
71
|
-
count = (neighbors_for(x, y) & cells).size
|
72
|
-
min = MIN[!!binary_search(cells, [x, y])] # .include? [x, y]]
|
73
|
-
count.between? min, 3
|
74
|
-
end
|
75
|
-
|
76
|
-
def neighbors_for x, y
|
77
|
-
@@neighbors[x][y] ||=
|
78
|
-
DELTAS.map { |(dx, dy)| [x+dx, y+dy] }.reject { |(m, n)| m < 0 || n < 0 }
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
size, width, count = 20, 32, 256
|
83
|
-
|
84
|
-
gol = GameOfLife.new
|
85
|
-
gol.randomize width, count
|
86
|
-
|
87
|
-
if ARGV.first == "prof" then
|
88
|
-
gol.run 50 do |n|
|
89
|
-
$stderr.print "."
|
90
|
-
end
|
91
|
-
warn "done"
|
92
|
-
else
|
93
|
-
require "sdl"
|
94
|
-
|
95
|
-
SDL.init SDL::INIT_VIDEO
|
96
|
-
SDL::WM::set_caption "Conway's Game of Life", "Conway's Game of Life"
|
97
|
-
|
98
|
-
screen = SDL::Screen.open 640, 640, 16, SDL::DOUBLEBUF
|
99
|
-
|
100
|
-
black = screen.format.map_rgb 0, 0, 0
|
101
|
-
white = screen.format.map_rgb 255, 255, 255
|
102
|
-
|
103
|
-
w, h = screen.w, screen.h
|
104
|
-
|
105
|
-
gol.run do
|
106
|
-
screen.fill_rect 0, 0, w, h, black
|
107
|
-
|
108
|
-
gol.cells.each do |(x, y)|
|
109
|
-
screen.fill_rect x*size, y*size, size-1, size-1, white
|
110
|
-
end
|
111
|
-
|
112
|
-
screen.flip
|
113
|
-
|
114
|
-
while event = SDL::Event.poll
|
115
|
-
case event
|
116
|
-
when SDL::Event::KeyDown, SDL::Event::Quit
|
117
|
-
exit
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
gol.update
|
122
|
-
end
|
123
|
-
end
|
data/examples/zenspider3.rb
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
#!/usr/bin/ruby -w
|
2
|
-
|
3
|
-
srand 42
|
4
|
-
|
5
|
-
class Array
|
6
|
-
def sorted_include? o
|
7
|
-
a, b = o
|
8
|
-
!!bsearch { |(x, y)|
|
9
|
-
c = a - x
|
10
|
-
c.zero? ? b - y : c
|
11
|
-
}
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class GameOfLife
|
16
|
-
delta = [-1, 0, 1]
|
17
|
-
same = [0, 0]
|
18
|
-
|
19
|
-
DELTAS = (delta.product(delta) - [same]).sort
|
20
|
-
MIN = { true => 2, false => 3 }
|
21
|
-
|
22
|
-
@@neighbors = Hash.new { |h, k| h[k] = {} }
|
23
|
-
|
24
|
-
attr_accessor :cells
|
25
|
-
attr_accessor :cache
|
26
|
-
|
27
|
-
def initialize
|
28
|
-
self.cells = []
|
29
|
-
end
|
30
|
-
|
31
|
-
def randomize n, m
|
32
|
-
dimensions = n.times.to_a
|
33
|
-
cells.replace dimensions.product(dimensions).sample(m).sort
|
34
|
-
end
|
35
|
-
|
36
|
-
def run max = 1.0 / 0
|
37
|
-
(1..max).each do |n|
|
38
|
-
yield n
|
39
|
-
update
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def update
|
44
|
-
cells.replace considered.select { |(x, y)| alive? x, y }.sort
|
45
|
-
end
|
46
|
-
|
47
|
-
def considered
|
48
|
-
cells.map { |(x, y)| neighbors_for(x, y) }.flatten(1).uniq
|
49
|
-
end
|
50
|
-
|
51
|
-
def alive? x, y
|
52
|
-
count = (neighbors_for(x, y) & cells).size
|
53
|
-
min = MIN[cells.sorted_include? [x, y]]
|
54
|
-
count.between? min, 3
|
55
|
-
end
|
56
|
-
|
57
|
-
def neighbors_for x, y
|
58
|
-
@@neighbors[x][y] ||=
|
59
|
-
DELTAS.map { |(dx, dy)| [x+dx, y+dy] }.reject { |(m, n)| m < 0 || n < 0 }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
size, width, count = 10, 64, 1000
|
64
|
-
|
65
|
-
gol = GameOfLife.new
|
66
|
-
gol.randomize width, count
|
67
|
-
|
68
|
-
if ARGV.first == "prof" then
|
69
|
-
gol.run 50 do |n|
|
70
|
-
$stderr.print "."
|
71
|
-
end
|
72
|
-
warn "done"
|
73
|
-
else
|
74
|
-
require "sdl"
|
75
|
-
|
76
|
-
SDL.init SDL::INIT_VIDEO
|
77
|
-
SDL::WM::set_caption "Conway's Game of Life", "Conway's Game of Life"
|
78
|
-
|
79
|
-
screen = SDL::Screen.open 640, 640, 16, SDL::DOUBLEBUF
|
80
|
-
|
81
|
-
black = screen.format.map_rgb 0, 0, 0
|
82
|
-
white = screen.format.map_rgb 255, 255, 255
|
83
|
-
|
84
|
-
w, h = screen.w, screen.h
|
85
|
-
|
86
|
-
gol.run do
|
87
|
-
screen.fill_rect 0, 0, w, h, black
|
88
|
-
|
89
|
-
gol.cells.each do |(x, y)|
|
90
|
-
screen.fill_rect x*size, y*size, size-1, size-1, white
|
91
|
-
end
|
92
|
-
|
93
|
-
screen.flip
|
94
|
-
|
95
|
-
while event = SDL::Event.poll
|
96
|
-
case event
|
97
|
-
when SDL::Event::KeyDown, SDL::Event::Quit
|
98
|
-
exit
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
gol.update
|
103
|
-
end
|
104
|
-
end
|
data/rubysdl_setup.sh
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
brew uninstall libogg
|
4
|
-
brew uninstall libvorbis
|
5
|
-
brew uninstall libpng
|
6
|
-
|
7
|
-
brew uninstall sdl
|
8
|
-
brew uninstall sdl_ttf
|
9
|
-
brew uninstall sdl_mixer
|
10
|
-
brew uninstall sdl_image
|
11
|
-
brew uninstall sge
|
12
|
-
|
13
|
-
# brew update
|
14
|
-
|
15
|
-
brew install libogg
|
16
|
-
brew install libvorbis
|
17
|
-
brew install libpng
|
18
|
-
|
19
|
-
brew install sdl
|
20
|
-
brew install sdl_mixer -- --with-libvorbis
|
21
|
-
brew install sdl_ttf
|
22
|
-
brew install sdl_image
|
23
|
-
|
24
|
-
gem uninstall -ax rsdl
|
25
|
-
gem uninstall -ax rubysdl
|
26
|
-
|
27
|
-
gem install rsdl
|
28
|
-
gem install rubysdl -- --enable-bundled-sge
|
29
|
-
|
30
|
-
ruby -r sdl -e 'p [:ttf, SDL.constants.include?(:TTF)]'
|
31
|
-
ruby -r sdl -e 'p [:mixer, SDL.constants.include?(:Mixer)]'
|
32
|
-
ruby -r sdl -e 'p [:sge, SDL.respond_to?(:auto_lock)]'
|
33
|
-
|
34
|
-
rsdl -r sdl -e 'SDL.init(SDL::INIT_EVERYTHING); SDL.set_video_mode(640, 480, 16, SDL::SWSURFACE); sleep(1)'
|