graphics 1.0.0b5 → 1.0.0b6
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 +38 -0
- data/Manifest.txt +5 -0
- data/Rakefile +2 -0
- data/examples/boid.rb +14 -15
- data/examples/bounce.rb +9 -11
- data/examples/canvas.rb +3 -1
- data/examples/collision.rb +10 -8
- data/examples/demo.rb +12 -12
- data/examples/fluid2.rb +13 -8
- data/examples/gol2.rb +0 -2
- data/examples/math.rb +3 -1
- data/examples/pi_polygon.rb +145 -0
- data/examples/radar.rb +3 -1
- data/examples/rainbow_fluid.rb +243 -0
- data/examples/tank.rb +19 -17
- data/examples/tank2.rb +25 -21
- data/examples/targeting.rb +3 -1
- data/examples/vants.rb +5 -21
- data/examples/walker.rb +15 -12
- data/examples/walker2.rb +28 -26
- data/examples/zombies.rb +0 -2
- data/ext/sdl/sdl.c +10 -3
- data/ext/sdl/sge/sge_primitives.cpp +11 -0
- data/ext/sdl/sge/sge_primitives.h +3 -0
- data/lib/graphics.rb +2 -1
- data/lib/graphics/body.rb +10 -25
- data/lib/graphics/decorators.rb +21 -0
- data/lib/graphics/rainbows.rb +128 -0
- data/lib/graphics/simulation.rb +139 -15
- data/test/test_graphics.rb +45 -9
- data/test/test_rainbows.rb +95 -0
- metadata +20 -28
- metadata.gz.sig +0 -0
data/test/test_graphics.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
require "minitest/autorun"
|
4
|
-
|
5
|
-
$: << File.expand_path("~/Work/p4/zss/src/minitest-focus/dev/lib")
|
6
|
-
require "minitest/focus"
|
7
|
-
|
8
4
|
require "graphics"
|
9
5
|
|
10
6
|
class TestBody < Minitest::Test
|
@@ -105,16 +101,56 @@ class TestBody < Minitest::Test
|
|
105
101
|
assert_in_delta 45, b.m_a[1]
|
106
102
|
end
|
107
103
|
|
108
|
-
def
|
104
|
+
def test_bounce_east
|
109
105
|
b.x = 99
|
110
106
|
b.a = 45
|
111
107
|
|
112
|
-
assert_body 99, 50,
|
108
|
+
assert_body 99, 50, 10, 45, 0, b
|
109
|
+
|
110
|
+
# dist_to_wall_x = w.w - b.x :: 1
|
111
|
+
# m_over_xy = b.m / Math.sqrt(2) :: 7.0710678
|
112
|
+
# bounce_x = m_over_xy - dist_to_wall_x :: 6.0710678
|
113
|
+
|
114
|
+
b.move
|
115
|
+
b.bounce
|
116
|
+
|
117
|
+
assert_body w.w-6.07106, 57.07106, 8, 135, 0, b
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_bounce_west
|
121
|
+
b.x = 1
|
122
|
+
b.a = 135
|
123
|
+
|
124
|
+
assert_body 1, 50, 10, 135, 0, b
|
125
|
+
|
126
|
+
b.move
|
127
|
+
b.bounce
|
128
|
+
|
129
|
+
assert_body 6.07106, w.h-42.929, 8, 45, 0, b
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_bounce_north
|
133
|
+
b.y = 99
|
134
|
+
b.a = 45
|
135
|
+
|
136
|
+
assert_body 50, 99, 10, 45, 0, b
|
137
|
+
|
138
|
+
b.move
|
139
|
+
b.bounce
|
140
|
+
|
141
|
+
assert_body 57.071, w.h-6.071, 8, 315, 0, b
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_bounce_south
|
145
|
+
b.y = 1
|
146
|
+
b.a = 315
|
147
|
+
|
148
|
+
assert_body 50, 1, 10, 315, 0, b
|
113
149
|
|
114
150
|
b.move
|
115
151
|
b.bounce
|
116
152
|
|
117
|
-
assert_body
|
153
|
+
assert_body 57.071, 6.071, 8, 45, 0, b
|
118
154
|
end
|
119
155
|
|
120
156
|
def test_clip
|
@@ -125,7 +161,7 @@ class TestBody < Minitest::Test
|
|
125
161
|
b.move
|
126
162
|
b.clip
|
127
163
|
|
128
|
-
assert_body
|
164
|
+
assert_body 91, 50, 10, 0, 0, b
|
129
165
|
end
|
130
166
|
|
131
167
|
def test_clip_off_wall
|
@@ -137,7 +173,7 @@ class TestBody < Minitest::Test
|
|
137
173
|
b.move
|
138
174
|
b.clip_off_wall
|
139
175
|
|
140
|
-
assert_body
|
176
|
+
assert_body 91, 50, 10, 0, 186, b
|
141
177
|
end
|
142
178
|
|
143
179
|
def test_move
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'graphics'
|
3
|
+
require 'graphics/rainbows'
|
4
|
+
|
5
|
+
class RainbowsTest < Minitest::Test
|
6
|
+
|
7
|
+
def setup
|
8
|
+
@greyscale = Graphics::Greyscale.new
|
9
|
+
@hue = Graphics::Hue.new
|
10
|
+
@cubehelix = Graphics::Cubehelix.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_clamping
|
14
|
+
assert_equal 360, @hue.clamp(10000, 0, 360)
|
15
|
+
assert_equal 0, @hue.clamp(-20, 0, 360)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_scaling_clamps_values
|
19
|
+
assert_equal 360, @hue.scale(10000, 0, 360)
|
20
|
+
assert_equal 0, @hue.scale(-20, 0, 360)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_scaling
|
24
|
+
# (We use assert_same instead of _equal to make sure we're
|
25
|
+
# really getting integers back)
|
26
|
+
assert_same 0, @hue.scale(0, 0, 360)
|
27
|
+
assert_same 180, @hue.scale(180, 0, 360)
|
28
|
+
assert_same 360, @hue.scale(360, 0, 360)
|
29
|
+
assert_same 30, @hue.scale(30, 0, 360)
|
30
|
+
# From smaller ranges
|
31
|
+
assert_same 0, @hue.scale(0, 180, 360)
|
32
|
+
assert_same 180, @hue.scale(50, 0, 100)
|
33
|
+
# From larger ranges
|
34
|
+
assert_same 180, @hue.scale(400, 100, 900)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_greyscale
|
38
|
+
assert_equal [0, 0, 0], @greyscale.color(0)# Black
|
39
|
+
assert_equal [127, 127, 127], @greyscale.color(180) # Mid-grey
|
40
|
+
assert_equal [255, 255, 255], @greyscale.color(360) # White
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_rainbow_start_and_end
|
44
|
+
# Half a greyscale spectrum
|
45
|
+
assert_equal [127, 127, 127], @greyscale.color(50, 0, 100)
|
46
|
+
assert_equal [255, 255, 255], @greyscale.color(1000, 0, 100)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_hue
|
50
|
+
assert_equal [255, 0, 0], @hue.color(0) # Red
|
51
|
+
assert_equal [255, 127, 0], @hue.color(30) # Orange
|
52
|
+
assert_equal [255, 255, 0], @hue.color(60) # Yellow
|
53
|
+
assert_equal [0, 255, 0], @hue.color(120) # Green
|
54
|
+
assert_equal [0, 255, 255], @hue.color(180) # Cyan
|
55
|
+
assert_equal [0, 0, 255], @hue.color(240) # Blue
|
56
|
+
assert_equal [255, 0, 255], @hue.color(300) # Magenta
|
57
|
+
assert_equal [255, 0, 0], @hue.color(360) # Red
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_cubehelix
|
61
|
+
# Cubehelix reference values from James Davenport's Python implementation
|
62
|
+
# Using:
|
63
|
+
# start = 0.5
|
64
|
+
# rotations = -1.5
|
65
|
+
# saturation = 1.2
|
66
|
+
# gamma = 1.0
|
67
|
+
# NOTE(Lito): These values are slightly different from my Ruby
|
68
|
+
# implementation. This could be floating-point error, or because
|
69
|
+
# cubehelix uses a slightly different scale (1-256 vs 0-360).
|
70
|
+
reference_values = [[0.0, 0.0, 0.0], # 0
|
71
|
+
[0.052086060929534689, 0.34174526961141383, 0.30658807547214501], # 90
|
72
|
+
[0.65901854013946559, 0.46936557468373608, 0.24845035363356044], # 180
|
73
|
+
[0.78295958648052344, 0.69774239781785263, 0.96714049479106534], # 270
|
74
|
+
[1.0, 1.0, 1.0]] # 360
|
75
|
+
# Move the colors from 0-1 scale to a 0-255 scale
|
76
|
+
rgb_255_reference = reference_values.map do |rgb|
|
77
|
+
rgb.map do |color|
|
78
|
+
(color*255).round
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def assert_arr_in_delta exp, act, delta
|
83
|
+
exp.zip(act) do |e, a|
|
84
|
+
assert_in_delta e, a, delta
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
assert_arr_in_delta rgb_255_reference[0], @cubehelix.color(0), 2
|
89
|
+
assert_arr_in_delta rgb_255_reference[1], @cubehelix.color(90), 2
|
90
|
+
assert_arr_in_delta rgb_255_reference[2], @cubehelix.color(180), 2
|
91
|
+
assert_arr_in_delta rgb_255_reference[3], @cubehelix.color(270), 2
|
92
|
+
assert_arr_in_delta rgb_255_reference[4], @cubehelix.color(360), 2
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.0b6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Davis
|
@@ -10,9 +10,9 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
13
|
+
MIIDijCCAnKgAwIBAgIBATANBgkqhkiG9w0BAQUFADBFMRMwEQYDVQQDDApyeWFu
|
14
14
|
ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
|
15
|
-
|
15
|
+
GRYDY29tMB4XDTE2MDkyNjAxNTczNVoXDTE3MDkyNjAxNTczNVowRTETMBEGA1UE
|
16
16
|
AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
|
17
17
|
JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
|
18
18
|
b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
|
@@ -20,16 +20,17 @@ cert_chain:
|
|
20
20
|
oOvjtt5P8+GSK9zLzxQP0gVLS/D0FmoE44XuDr3iQkVS2ujU5zZL84mMNqNB1znh
|
21
21
|
GiadM9GHRaDiaxuX0cIUBj19T01mVE2iymf9I6bEsiayK/n6QujtyCbTWsAS9Rqt
|
22
22
|
qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
|
23
|
-
gBEfoTEGr7Zii72cx+
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
gBEfoTEGr7Zii72cx+sCAwEAAaOBhDCBgTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
|
24
|
+
sDAdBgNVHQ4EFgQUR8V72Z3+v+2P9abCnL4wjx32T+EwIwYDVR0RBBwwGoEYcnlh
|
25
|
+
bmQtcnVieUB6ZW5zcGlkZXIuY29tMCMGA1UdEgQcMBqBGHJ5YW5kLXJ1YnlAemVu
|
26
|
+
c3BpZGVyLmNvbTANBgkqhkiG9w0BAQUFAAOCAQEAIGzgp0aZ2W9+v96ujmBcQHoC
|
27
|
+
buy0iU68MVj2VlxMyfr1KPZIh1OyhU4UO4zrkREcH8ML70v9cYHNvOd9oynRHnvC
|
28
|
+
l2tj/fD3YJ0AEkJxGrYwRWQmvMfC4bJ02bC1+rVOUIXXKp3+cUmiN4sTniof8VFo
|
29
|
+
bo/YYP4c7erpERa+9hrqygg6WQbJlk2YRlH3JXPFjmu869i2dcbR5ZLOAeEy+axH
|
30
|
+
E4oJcnPkJAr0rw504JGtlZtONZQblwmRJOIdXzolaE3NRGUzGVOUSptZppAKiavY
|
31
|
+
fO6tdKQc/5RfA8oQEkg8hrxA5PQSz4TOFJGLpFvIapEk6tMruQ0bHgkhr9auXg==
|
31
32
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
33
|
+
date: 2016-11-17 00:00:00.000000000 Z
|
33
34
|
dependencies:
|
34
35
|
- !ruby/object:Gem::Dependency
|
35
36
|
name: rsdl
|
@@ -45,20 +46,6 @@ dependencies:
|
|
45
46
|
- - ~>
|
46
47
|
- !ruby/object:Gem::Version
|
47
48
|
version: '0.1'
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: minitest
|
50
|
-
requirement: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ~>
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5.8'
|
55
|
-
type: :development
|
56
|
-
prerelease: false
|
57
|
-
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '5.8'
|
62
49
|
- !ruby/object:Gem::Dependency
|
63
50
|
name: rdoc
|
64
51
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,14 +80,14 @@ dependencies:
|
|
93
80
|
requirements:
|
94
81
|
- - ~>
|
95
82
|
- !ruby/object:Gem::Version
|
96
|
-
version: '3.
|
83
|
+
version: '3.15'
|
97
84
|
type: :development
|
98
85
|
prerelease: false
|
99
86
|
version_requirements: !ruby/object:Gem::Requirement
|
100
87
|
requirements:
|
101
88
|
- - ~>
|
102
89
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3.
|
90
|
+
version: '3.15'
|
104
91
|
description: |-
|
105
92
|
Graphics provides a simple framework to implement games and/or
|
106
93
|
simulations and is designed to follow mathematical conventions, NOT
|
@@ -142,7 +129,9 @@ files:
|
|
142
129
|
- examples/logo.rb
|
143
130
|
- examples/math.rb
|
144
131
|
- examples/maze.rb
|
132
|
+
- examples/pi_polygon.rb
|
145
133
|
- examples/radar.rb
|
134
|
+
- examples/rainbow_fluid.rb
|
146
135
|
- examples/tank.rb
|
147
136
|
- examples/tank2.rb
|
148
137
|
- examples/targeting.rb
|
@@ -185,13 +174,16 @@ files:
|
|
185
174
|
- graphics_setup.sh
|
186
175
|
- lib/graphics.rb
|
187
176
|
- lib/graphics/body.rb
|
177
|
+
- lib/graphics/decorators.rb
|
188
178
|
- lib/graphics/extensions.rb
|
179
|
+
- lib/graphics/rainbows.rb
|
189
180
|
- lib/graphics/simulation.rb
|
190
181
|
- lib/graphics/trail.rb
|
191
182
|
- lib/graphics/v.rb
|
192
183
|
- resources/images/body.png
|
193
184
|
- resources/images/turret.png
|
194
185
|
- test/test_graphics.rb
|
186
|
+
- test/test_rainbows.rb
|
195
187
|
- test/test_sdl.rb
|
196
188
|
homepage: https://github.com/zenspider/graphics
|
197
189
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|