sgl 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +254 -234
- data/History.txt +6 -0
- data/Manifest.txt +10 -0
- data/Rakefile +27 -7
- data/examples/cocoa1-basic.rb +14 -14
- data/examples/cocoa10-transparent.rb +26 -26
- data/examples/cocoa11-application.rb +13 -13
- data/examples/cocoa2-draw.rb +23 -23
- data/examples/cocoa3-affine.rb +29 -29
- data/examples/cocoa4-font.rb +24 -24
- data/examples/cocoa5-image.rb +22 -22
- data/examples/cocoa6-sound.rb +24 -24
- data/examples/cocoa7-movie.rb +40 -40
- data/examples/cocoa8-movieoverlay.rb +42 -42
- data/examples/cocoa9-streaming.rb +40 -40
- data/examples/opengl1-basic.rb +14 -14
- data/examples/opengl11-application.rb +13 -13
- data/examples/opengl2-draw.rb +23 -23
- data/examples/opengl3-affine.rb +29 -29
- data/examples/sample1.rb +11 -11
- data/examples/sample10.rb +16 -16
- data/examples/sample11.rb +22 -22
- data/examples/sample11a.rb +33 -33
- data/examples/sample12.rb +30 -30
- data/examples/sample12a.rb +35 -35
- data/examples/sample13.rb +116 -116
- data/examples/sample15.rb +24 -24
- data/examples/sample16.rb +31 -31
- data/examples/sample16a.rb +35 -35
- data/examples/sample6.rb +18 -18
- data/examples/sample7.rb +16 -16
- data/examples/sample9.rb +20 -20
- data/examples/testgl.rb +169 -169
- data/lib/sgl/bass.rb +46 -46
- data/lib/sgl/cocoa-app.rb +43 -43
- data/lib/sgl/cocoa-color.rb +65 -65
- data/lib/sgl/cocoa-draw.rb +72 -72
- data/lib/sgl/cocoa-event.rb +229 -229
- data/lib/sgl/cocoa-media.rb +144 -144
- data/lib/sgl/cocoa-notuse.rb +493 -493
- data/lib/sgl/cocoa-window.rb +203 -203
- data/lib/sgl/cocoa.rb +8 -8
- data/lib/sgl/opengl-app.rb +38 -38
- data/lib/sgl/opengl-color.rb +44 -44
- data/lib/sgl/opengl-draw.rb +260 -260
- data/lib/sgl/opengl-event.rb +325 -325
- data/lib/sgl/opengl-modules.rb +22 -22
- data/lib/sgl/opengl-window.rb +224 -224
- data/lib/sgl/opengl.rb +7 -7
- data/lib/sgl/sgl-button.rb +135 -135
- data/lib/sgl/sgl-client.rb +21 -21
- data/lib/sgl/sgl-color.rb +68 -82
- data/lib/sgl/sgl-connect.rb +9 -9
- data/lib/sgl/sgl-server.rb +58 -58
- data/lib/sgl/sgl-spring.rb +216 -216
- data/lib/sgl/version.rb +2 -2
- data/scripts/lib-txt2html.rb +130 -0
- data/scripts/txt2html +2 -63
- data/spec/sgl_spec.rb +13 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +1 -0
- data/test/test_cocoa_app.rb +291 -291
- data/test/test_module_ruby16.rb +30 -30
- data/test/test_opengl_app.rb +147 -147
- data/test/test_opengl_basic.rb +22 -22
- data/test/test_opengl_fullscreen.rb +23 -23
- data/test/test_opengl_novice.rb +35 -35
- data/website/challenge1.html +91 -91
- data/website/challenge1.txt +3 -3
- data/website/challenge2.html +143 -144
- data/website/challenge2.txt +13 -14
- data/website/challenge3.html +66 -63
- data/website/challenge3.txt +7 -7
- data/website/cocoa.html +85 -88
- data/website/cocoa.txt +2 -4
- data/website/description.html +138 -138
- data/website/description.txt +1 -1
- data/website/exercise1.html +262 -264
- data/website/exercise1.txt +58 -53
- data/website/exercise2.html +241 -683
- data/website/exercise2.txt +11 -427
- data/website/exercise3.html +206 -0
- data/website/exercise3.txt +155 -0
- data/website/exercise4.html +198 -0
- data/website/exercise4.txt +151 -0
- data/website/exercise5.html +162 -0
- data/website/exercise5.txt +113 -0
- data/website/exhibition.html +84 -84
- data/website/howto.html +146 -134
- data/website/howto.txt +9 -0
- data/website/index.html +178 -178
- data/website/index.txt +20 -19
- data/website/sound.html +141 -141
- metadata +16 -3
data/lib/sgl/opengl.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
-
# License: Ruby License
|
3
|
-
|
4
|
-
require "sgl/opengl-app"
|
5
|
-
|
6
|
-
include SGL
|
7
|
-
$__a__ = Application.new
|
1
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
+
# License: Ruby License
|
3
|
+
|
4
|
+
require "sgl/opengl-app"
|
5
|
+
|
6
|
+
include SGL
|
7
|
+
$__a__ = Application.new
|
data/lib/sgl/sgl-button.rb
CHANGED
@@ -1,135 +1,135 @@
|
|
1
|
-
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
-
# License: Ruby License
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift("..") if !$LOAD_PATH.include?("..")
|
5
|
-
require "sgl/opengl"
|
6
|
-
require "sgl/sgl-spring"
|
7
|
-
|
8
|
-
class Button
|
9
|
-
def initialize(x, y)
|
10
|
-
@dx, @dy = x, y
|
11
|
-
@x, @y = x, y
|
12
|
-
@w, @h = 8, 8
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_accessor :x, :y
|
16
|
-
|
17
|
-
def pos
|
18
|
-
return [x, y]
|
19
|
-
end
|
20
|
-
|
21
|
-
def move_to(x, y)
|
22
|
-
@x, @y = x, y
|
23
|
-
end
|
24
|
-
|
25
|
-
def draw(s)
|
26
|
-
colorHSV(0, s, 100, 60)
|
27
|
-
draw_rect(@w, @h)
|
28
|
-
colorHSV(0, s, 0, 30)
|
29
|
-
draw_rect(@w-1, @h-1)
|
30
|
-
end
|
31
|
-
|
32
|
-
def draw_rect(w, h)
|
33
|
-
rect(@x-w, @y-h, @x+w, @y+h)
|
34
|
-
end
|
35
|
-
|
36
|
-
def inside?(x, y)
|
37
|
-
(@x-@w) < x && x < (@x+@w) && (@y-@h) < y && y < (@y+@h)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class ButtonColumn
|
42
|
-
def initialize(length, dy, hy)
|
43
|
-
@length, @dy, @hy = length, dy, hy #destination y and hide y
|
44
|
-
@cur = 0
|
45
|
-
@buttons = []
|
46
|
-
@y_spring = NumSpring.new(@dy, @dy, 5, 0.6)
|
47
|
-
make_buttons
|
48
|
-
end
|
49
|
-
|
50
|
-
attr_reader :y_spring
|
51
|
-
attr_accessor :cur
|
52
|
-
|
53
|
-
def make_buttons
|
54
|
-
y = @y_spring.x
|
55
|
-
sw = 46
|
56
|
-
w = 0
|
57
|
-
@length.times {
|
58
|
-
@buttons << Button.new(0, y)
|
59
|
-
w += sw
|
60
|
-
}
|
61
|
-
x = -w/2
|
62
|
-
@buttons.each {|b|
|
63
|
-
b.x = x
|
64
|
-
x += sw
|
65
|
-
}
|
66
|
-
end
|
67
|
-
|
68
|
-
def move(x, y)
|
69
|
-
# @y_spring.target = y.abs < (768/2 - 120) ? @hy : @dy
|
70
|
-
#if y.abs < (768/2 - 120)
|
71
|
-
if (@dy - y).abs < 50
|
72
|
-
@y_spring.target = @dy
|
73
|
-
else
|
74
|
-
@y_spring.target = @hy
|
75
|
-
end
|
76
|
-
@y_spring.moving = true
|
77
|
-
@y_spring.move
|
78
|
-
y = @y_spring.x
|
79
|
-
@buttons.each {|b|
|
80
|
-
b.y = y
|
81
|
-
}
|
82
|
-
end
|
83
|
-
|
84
|
-
def draw
|
85
|
-
@buttons.each_index {|i|
|
86
|
-
b = @buttons[i]
|
87
|
-
s = (@cur == i) ? 100 : 0
|
88
|
-
b.draw(s)
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
def onMouseDown(x, y)
|
93
|
-
@buttons.each_index {|i|
|
94
|
-
b = @buttons[i]
|
95
|
-
if b.inside?(x, y)
|
96
|
-
@cur = i
|
97
|
-
return i
|
98
|
-
end
|
99
|
-
}
|
100
|
-
nil
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
if $0 == __FILE__
|
105
|
-
require "test/unit"
|
106
|
-
$__test_sgl__ = true
|
107
|
-
end
|
108
|
-
|
109
|
-
if defined?($__test_sgl__) && $__test_sgl__
|
110
|
-
class TestSglButton < Test::Unit::TestCase #:nodoc:
|
111
|
-
def test_button
|
112
|
-
b = Button.new(1, 2)
|
113
|
-
assert_equal(1, b.x)
|
114
|
-
assert_equal(2, b.y)
|
115
|
-
assert_equal([1, 2], b.pos)
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_draw
|
119
|
-
app = SGL::Application.new
|
120
|
-
app.set_setup {
|
121
|
-
app.window(100, 100)
|
122
|
-
app.runtime = 0.1
|
123
|
-
}
|
124
|
-
i = 0
|
125
|
-
button = Button.new(0, 0)
|
126
|
-
app.set_display {
|
127
|
-
button.move_to(i, i)
|
128
|
-
button.draw(i)
|
129
|
-
i += 5
|
130
|
-
i = 0 if 100 < i
|
131
|
-
}
|
132
|
-
app.mainloop
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
1
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
2
|
+
# License: Ruby License
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift("..") if !$LOAD_PATH.include?("..")
|
5
|
+
require "sgl/opengl"
|
6
|
+
require "sgl/sgl-spring"
|
7
|
+
|
8
|
+
class Button
|
9
|
+
def initialize(x, y)
|
10
|
+
@dx, @dy = x, y
|
11
|
+
@x, @y = x, y
|
12
|
+
@w, @h = 8, 8
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_accessor :x, :y
|
16
|
+
|
17
|
+
def pos
|
18
|
+
return [x, y]
|
19
|
+
end
|
20
|
+
|
21
|
+
def move_to(x, y)
|
22
|
+
@x, @y = x, y
|
23
|
+
end
|
24
|
+
|
25
|
+
def draw(s)
|
26
|
+
colorHSV(0, s, 100, 60)
|
27
|
+
draw_rect(@w, @h)
|
28
|
+
colorHSV(0, s, 0, 30)
|
29
|
+
draw_rect(@w-1, @h-1)
|
30
|
+
end
|
31
|
+
|
32
|
+
def draw_rect(w, h)
|
33
|
+
rect(@x-w, @y-h, @x+w, @y+h)
|
34
|
+
end
|
35
|
+
|
36
|
+
def inside?(x, y)
|
37
|
+
(@x-@w) < x && x < (@x+@w) && (@y-@h) < y && y < (@y+@h)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class ButtonColumn
|
42
|
+
def initialize(length, dy, hy)
|
43
|
+
@length, @dy, @hy = length, dy, hy #destination y and hide y
|
44
|
+
@cur = 0
|
45
|
+
@buttons = []
|
46
|
+
@y_spring = NumSpring.new(@dy, @dy, 5, 0.6)
|
47
|
+
make_buttons
|
48
|
+
end
|
49
|
+
|
50
|
+
attr_reader :y_spring
|
51
|
+
attr_accessor :cur
|
52
|
+
|
53
|
+
def make_buttons
|
54
|
+
y = @y_spring.x
|
55
|
+
sw = 46
|
56
|
+
w = 0
|
57
|
+
@length.times {
|
58
|
+
@buttons << Button.new(0, y)
|
59
|
+
w += sw
|
60
|
+
}
|
61
|
+
x = -w/2
|
62
|
+
@buttons.each {|b|
|
63
|
+
b.x = x
|
64
|
+
x += sw
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
def move(x, y)
|
69
|
+
# @y_spring.target = y.abs < (768/2 - 120) ? @hy : @dy
|
70
|
+
#if y.abs < (768/2 - 120)
|
71
|
+
if (@dy - y).abs < 50
|
72
|
+
@y_spring.target = @dy
|
73
|
+
else
|
74
|
+
@y_spring.target = @hy
|
75
|
+
end
|
76
|
+
@y_spring.moving = true
|
77
|
+
@y_spring.move
|
78
|
+
y = @y_spring.x
|
79
|
+
@buttons.each {|b|
|
80
|
+
b.y = y
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def draw
|
85
|
+
@buttons.each_index {|i|
|
86
|
+
b = @buttons[i]
|
87
|
+
s = (@cur == i) ? 100 : 0
|
88
|
+
b.draw(s)
|
89
|
+
}
|
90
|
+
end
|
91
|
+
|
92
|
+
def onMouseDown(x, y)
|
93
|
+
@buttons.each_index {|i|
|
94
|
+
b = @buttons[i]
|
95
|
+
if b.inside?(x, y)
|
96
|
+
@cur = i
|
97
|
+
return i
|
98
|
+
end
|
99
|
+
}
|
100
|
+
nil
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
if $0 == __FILE__
|
105
|
+
require "test/unit"
|
106
|
+
$__test_sgl__ = true
|
107
|
+
end
|
108
|
+
|
109
|
+
if defined?($__test_sgl__) && $__test_sgl__
|
110
|
+
class TestSglButton < Test::Unit::TestCase #:nodoc:
|
111
|
+
def test_button
|
112
|
+
b = Button.new(1, 2)
|
113
|
+
assert_equal(1, b.x)
|
114
|
+
assert_equal(2, b.y)
|
115
|
+
assert_equal([1, 2], b.pos)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_draw
|
119
|
+
app = SGL::Application.new
|
120
|
+
app.set_setup {
|
121
|
+
app.window(100, 100)
|
122
|
+
app.runtime = 0.1
|
123
|
+
}
|
124
|
+
i = 0
|
125
|
+
button = Button.new(0, 0)
|
126
|
+
app.set_display {
|
127
|
+
button.move_to(i, i)
|
128
|
+
button.draw(i)
|
129
|
+
i += 5
|
130
|
+
i = 0 if 100 < i
|
131
|
+
}
|
132
|
+
app.mainloop
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/lib/sgl/sgl-client.rb
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
#!/usr/bin/env ruby -w
|
2
|
-
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
3
|
-
# License: Ruby License
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift("..") if !$LOAD_PATH.include?("..")
|
6
|
-
require "sgl/sgl-connect"
|
7
|
-
|
8
|
-
module Sgl
|
9
|
-
class Client
|
10
|
-
def self.main(argv)
|
11
|
-
uri = ARGV.shift
|
12
|
-
there = DRbObject.new_with_uri(uri)
|
13
|
-
there.puts('Hello, World.')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
if $0 == __FILE__
|
19
|
-
require "test/unit"
|
20
|
-
Sgl::Client.main(ARGV)
|
21
|
-
end
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
3
|
+
# License: Ruby License
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift("..") if !$LOAD_PATH.include?("..")
|
6
|
+
require "sgl/sgl-connect"
|
7
|
+
|
8
|
+
module Sgl
|
9
|
+
class Client
|
10
|
+
def self.main(argv)
|
11
|
+
uri = ARGV.shift
|
12
|
+
there = DRbObject.new_with_uri(uri)
|
13
|
+
there.puts('Hello, World.')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
if $0 == __FILE__
|
19
|
+
require "test/unit"
|
20
|
+
Sgl::Client.main(ARGV)
|
21
|
+
end
|
data/lib/sgl/sgl-color.rb
CHANGED
@@ -1,82 +1,68 @@
|
|
1
|
-
#!/usr/bin/env ruby -w
|
2
|
-
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
3
|
-
# License: Ruby License
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift("..") if !$LOAD_PATH.include?("..")
|
6
|
-
|
7
|
-
module SGL
|
8
|
-
RGB = 0
|
9
|
-
HSV = 1
|
10
|
-
DEFAULT_MAX = 100
|
11
|
-
|
12
|
-
class ColorTranslatorRGB
|
13
|
-
def initialize(r=nil, g=nil, b=nil, a=nil)
|
14
|
-
a = DEFAULT_MAX if a == nil
|
15
|
-
r = DEFAULT_MAX if r == nil
|
16
|
-
g = b = r if g == nil || b == nil
|
17
|
-
@rm, @gm, @bm, @am = r.to_f, g.to_f, b.to_f, a.to_f
|
18
|
-
end
|
19
|
-
|
20
|
-
def norm(r, g=nil, b=nil, a=nil)
|
21
|
-
a = DEFAULT_MAX if a == nil
|
22
|
-
g = b = r if g == nil || b == nil
|
23
|
-
return [r/@rm, g/@gm, b/@bm, a/@am]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
class ColorTranslatorHSV
|
28
|
-
def initialize(h=nil, s=nil, v=nil, a=nil)
|
29
|
-
a = DEFAULT_MAX if a == nil
|
30
|
-
h = DEFAULT_MAX if h == nil
|
31
|
-
s = v = h if s == nil || v == nil
|
32
|
-
@hm, @sm, @vm, @am = h.to_f, s.to_f, v.to_f, a.to_f
|
33
|
-
end
|
34
|
-
|
35
|
-
def norm(h, s=nil, v=nil, a=nil)
|
36
|
-
if h < 0
|
37
|
-
base = (h.abs / @hm).to_i + 1
|
38
|
-
h += (base * @hm).to_f
|
39
|
-
end
|
40
|
-
h = (h % @hm) if @hm < h
|
41
|
-
a = DEFAULT_MAX if a == nil
|
42
|
-
s = v = h if s == nil || v == nil
|
43
|
-
r, g, b = hsv_to_rgb(360.0*h/@hm, s/@sm, v/@vm)
|
44
|
-
return [r, g, b, a/@am]
|
45
|
-
end
|
46
|
-
|
47
|
-
def hsv_to_rgb(h, s, v) #h:[0-360] s,v:[0,1], r,g,b:[0,1]
|
48
|
-
return v, v, v if s == 0.0
|
49
|
-
h = 0 if h == 360
|
50
|
-
h /= 60.0 #h is now [0,6)
|
51
|
-
i = h.to_i
|
52
|
-
f = (h-i).to_f
|
53
|
-
pp = v * (1-s)
|
54
|
-
q = v * (1-(s*f))
|
55
|
-
t = v * (1-(s*(1-f)))
|
56
|
-
#p [h,s,v, i, f, pp, q, t]
|
57
|
-
case i
|
58
|
-
when 0; return v, t, pp
|
59
|
-
when 1; return q, v, pp
|
60
|
-
when 2; return pp, v, t
|
61
|
-
when 3; return pp, q, v
|
62
|
-
when 4; return t, pp, v
|
63
|
-
when 5; return v, pp, q
|
64
|
-
end
|
65
|
-
return 0, 0, 0
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
if $0 == __FILE__
|
71
|
-
require "test/unit"
|
72
|
-
$__test_sgl__ = true
|
73
|
-
end
|
74
|
-
|
75
|
-
if defined?($__test_sgl__) && $__test_sgl__
|
76
|
-
class TestSglColor_SglColor < Test::Unit::TestCase #:nodoc:
|
77
|
-
def test_all
|
78
|
-
rgb = SGL::ColorTranslatorRGB.new(100, 100, 100, 100)
|
79
|
-
assert_equal([1.0, 1.0, 1.0, 1.0], rgb.norm(100, 100, 100))
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
# Copyright (C) 2004-2007 Kouichirou Eto, All rights reserved.
|
3
|
+
# License: Ruby License
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift("..") if !$LOAD_PATH.include?("..")
|
6
|
+
|
7
|
+
module SGL
|
8
|
+
RGB = 0
|
9
|
+
HSV = 1
|
10
|
+
DEFAULT_MAX = 100
|
11
|
+
|
12
|
+
class ColorTranslatorRGB
|
13
|
+
def initialize(r=nil, g=nil, b=nil, a=nil)
|
14
|
+
a = DEFAULT_MAX if a == nil
|
15
|
+
r = DEFAULT_MAX if r == nil
|
16
|
+
g = b = r if g == nil || b == nil
|
17
|
+
@rm, @gm, @bm, @am = r.to_f, g.to_f, b.to_f, a.to_f
|
18
|
+
end
|
19
|
+
|
20
|
+
def norm(r, g=nil, b=nil, a=nil)
|
21
|
+
a = DEFAULT_MAX if a == nil
|
22
|
+
g = b = r if g == nil || b == nil
|
23
|
+
return [r/@rm, g/@gm, b/@bm, a/@am]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class ColorTranslatorHSV
|
28
|
+
def initialize(h=nil, s=nil, v=nil, a=nil)
|
29
|
+
a = DEFAULT_MAX if a == nil
|
30
|
+
h = DEFAULT_MAX if h == nil
|
31
|
+
s = v = h if s == nil || v == nil
|
32
|
+
@hm, @sm, @vm, @am = h.to_f, s.to_f, v.to_f, a.to_f
|
33
|
+
end
|
34
|
+
|
35
|
+
def norm(h, s=nil, v=nil, a=nil)
|
36
|
+
if h < 0
|
37
|
+
base = (h.abs / @hm).to_i + 1
|
38
|
+
h += (base * @hm).to_f
|
39
|
+
end
|
40
|
+
h = (h % @hm) if @hm < h
|
41
|
+
a = DEFAULT_MAX if a == nil
|
42
|
+
s = v = h if s == nil || v == nil
|
43
|
+
r, g, b = hsv_to_rgb(360.0*h/@hm, s/@sm, v/@vm)
|
44
|
+
return [r, g, b, a/@am]
|
45
|
+
end
|
46
|
+
|
47
|
+
def hsv_to_rgb(h, s, v) #h:[0-360] s,v:[0,1], r,g,b:[0,1]
|
48
|
+
return v, v, v if s == 0.0
|
49
|
+
h = 0 if h == 360
|
50
|
+
h /= 60.0 #h is now [0,6)
|
51
|
+
i = h.to_i
|
52
|
+
f = (h-i).to_f
|
53
|
+
pp = v * (1-s)
|
54
|
+
q = v * (1-(s*f))
|
55
|
+
t = v * (1-(s*(1-f)))
|
56
|
+
#p [h,s,v, i, f, pp, q, t]
|
57
|
+
case i
|
58
|
+
when 0; return v, t, pp
|
59
|
+
when 1; return q, v, pp
|
60
|
+
when 2; return pp, v, t
|
61
|
+
when 3; return pp, q, v
|
62
|
+
when 4; return t, pp, v
|
63
|
+
when 5; return v, pp, q
|
64
|
+
end
|
65
|
+
return 0, 0, 0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|