rays 0.1.11 → 0.1.16
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.
- checksums.yaml +5 -5
- data/.doc/ext/rays/bitmap.cpp +22 -76
- data/.doc/ext/rays/bounds.cpp +95 -125
- data/.doc/ext/rays/camera.cpp +88 -0
- data/.doc/ext/rays/color.cpp +223 -45
- data/.doc/ext/rays/color_space.cpp +146 -46
- data/.doc/ext/rays/defs.cpp +183 -0
- data/.doc/ext/rays/font.cpp +69 -21
- data/.doc/ext/rays/image.cpp +26 -37
- data/.doc/ext/rays/matrix.cpp +186 -29
- data/.doc/ext/rays/native.cpp +14 -8
- data/.doc/ext/rays/noise.cpp +53 -0
- data/.doc/ext/rays/painter.cpp +187 -292
- data/.doc/ext/rays/point.cpp +96 -77
- data/.doc/ext/rays/polygon.cpp +313 -0
- data/.doc/ext/rays/polygon_line.cpp +96 -0
- data/.doc/ext/rays/polyline.cpp +167 -0
- data/.doc/ext/rays/rays.cpp +103 -12
- data/.doc/ext/rays/shader.cpp +83 -9
- data/LICENSE +21 -0
- data/README.md +1 -1
- data/Rakefile +24 -9
- data/VERSION +1 -1
- data/ext/rays/bitmap.cpp +22 -80
- data/ext/rays/bounds.cpp +100 -128
- data/ext/rays/camera.cpp +94 -0
- data/ext/rays/color.cpp +231 -51
- data/ext/rays/color_space.cpp +149 -47
- data/ext/rays/defs.cpp +183 -0
- data/ext/rays/defs.h +26 -2
- data/ext/rays/extconf.rb +2 -3
- data/ext/rays/font.cpp +74 -24
- data/ext/rays/image.cpp +28 -40
- data/ext/rays/matrix.cpp +198 -30
- data/ext/rays/native.cpp +14 -8
- data/ext/rays/noise.cpp +55 -0
- data/ext/rays/painter.cpp +203 -298
- data/ext/rays/point.cpp +105 -81
- data/ext/rays/polygon.cpp +329 -0
- data/ext/rays/polygon_line.cpp +99 -0
- data/ext/rays/polyline.cpp +176 -0
- data/ext/rays/rays.cpp +103 -13
- data/ext/rays/shader.cpp +84 -9
- data/include/rays.h +10 -2
- data/include/rays/bitmap.h +14 -26
- data/include/rays/bounds.h +21 -4
- data/include/rays/camera.h +49 -0
- data/include/rays/color.h +25 -14
- data/include/rays/color_space.h +15 -10
- data/include/rays/coord.h +114 -0
- data/include/rays/debug.h +22 -0
- data/include/rays/defs.h +36 -0
- data/include/rays/exception.h +6 -2
- data/include/rays/font.h +4 -4
- data/include/rays/image.h +12 -18
- data/include/rays/matrix.h +50 -24
- data/include/rays/noise.h +42 -0
- data/include/rays/opengl.h +2 -50
- data/include/rays/painter.h +89 -93
- data/include/rays/point.h +44 -51
- data/include/rays/polygon.h +198 -0
- data/include/rays/polyline.h +71 -0
- data/include/rays/rays.h +3 -0
- data/include/rays/ruby.h +7 -1
- data/include/rays/ruby/bounds.h +1 -1
- data/include/rays/ruby/camera.h +41 -0
- data/include/rays/ruby/color.h +1 -1
- data/include/rays/ruby/color_space.h +1 -1
- data/include/rays/ruby/font.h +1 -1
- data/include/rays/ruby/matrix.h +1 -1
- data/include/rays/ruby/point.h +1 -1
- data/include/rays/ruby/polygon.h +52 -0
- data/include/rays/ruby/polyline.h +41 -0
- data/include/rays/ruby/rays.h +8 -0
- data/include/rays/ruby/shader.h +1 -1
- data/include/rays/shader.h +36 -8
- data/lib/rays.rb +7 -2
- data/lib/rays/bitmap.rb +0 -15
- data/lib/rays/bounds.rb +17 -23
- data/lib/rays/camera.rb +21 -0
- data/lib/rays/color.rb +20 -47
- data/lib/rays/color_space.rb +13 -13
- data/lib/rays/image.rb +3 -7
- data/lib/rays/matrix.rb +28 -0
- data/lib/rays/module.rb +4 -19
- data/lib/rays/painter.rb +78 -93
- data/lib/rays/point.rb +13 -21
- data/lib/rays/polygon.rb +58 -0
- data/lib/rays/polygon_line.rb +36 -0
- data/lib/rays/polyline.rb +32 -0
- data/lib/rays/shader.rb +20 -1
- data/rays.gemspec +5 -7
- data/src/bitmap.h +36 -0
- data/src/bounds.cpp +74 -11
- data/src/color.cpp +58 -23
- data/src/color_space.cpp +52 -34
- data/src/color_space.h +22 -0
- data/src/coord.cpp +170 -0
- data/src/coord.h +35 -0
- data/src/font.cpp +118 -0
- data/src/font.h +64 -0
- data/src/frame_buffer.cpp +37 -71
- data/src/frame_buffer.h +4 -4
- data/src/image.cpp +172 -98
- data/src/image.h +25 -0
- data/src/ios/bitmap.h +21 -0
- data/src/ios/bitmap.mm +129 -110
- data/src/ios/camera.mm +236 -0
- data/src/ios/font.mm +50 -62
- data/src/ios/helper.h +2 -2
- data/src/ios/opengl.mm +19 -4
- data/src/ios/rays.mm +3 -0
- data/src/matrix.cpp +111 -26
- data/src/matrix.h +30 -0
- data/src/noise.cpp +74 -0
- data/src/opengl.cpp +9 -27
- data/src/opengl.h +37 -0
- data/src/osx/bitmap.h +21 -0
- data/src/osx/bitmap.mm +129 -110
- data/src/osx/camera.mm +236 -0
- data/src/osx/font.mm +49 -62
- data/src/osx/helper.h +2 -2
- data/src/osx/opengl.mm +19 -83
- data/src/osx/rays.mm +3 -0
- data/src/painter.cpp +845 -671
- data/src/painter.h +24 -0
- data/src/point.cpp +140 -119
- data/src/polygon.cpp +1266 -0
- data/src/polygon.h +32 -0
- data/src/polyline.cpp +160 -0
- data/src/polyline.h +69 -0
- data/src/render_buffer.cpp +11 -4
- data/src/render_buffer.h +2 -2
- data/src/shader.cpp +163 -106
- data/src/shader.h +38 -0
- data/src/shader_program.cpp +533 -0
- data/src/{program.h → shader_program.h} +28 -16
- data/src/shader_source.cpp +140 -0
- data/src/shader_source.h +52 -0
- data/src/texture.cpp +136 -160
- data/src/texture.h +65 -0
- data/src/win32/bitmap.cpp +62 -52
- data/src/win32/font.cpp +11 -13
- data/src/win32/font.h +24 -0
- data/src/win32/gdi.h +6 -6
- data/test/helper.rb +0 -3
- data/test/test_bitmap.rb +31 -7
- data/test/test_bounds.rb +36 -0
- data/test/test_color.rb +59 -19
- data/test/test_color_space.rb +95 -0
- data/test/test_font.rb +5 -0
- data/test/test_image.rb +24 -20
- data/test/test_matrix.rb +106 -0
- data/test/test_painter.rb +157 -51
- data/test/test_painter_shape.rb +102 -0
- data/test/test_point.rb +29 -0
- data/test/test_polygon.rb +234 -0
- data/test/test_polygon_line.rb +167 -0
- data/test/test_polyline.rb +171 -0
- data/test/test_shader.rb +9 -9
- metadata +102 -70
- data/.doc/ext/rays/texture.cpp +0 -138
- data/ext/rays/texture.cpp +0 -149
- data/include/rays/ruby/texture.h +0 -41
- data/include/rays/texture.h +0 -71
- data/lib/rays/texture.rb +0 -24
- data/src/program.cpp +0 -648
- data/test/test_texture.rb +0 -27
data/include/rays/ruby/bounds.h
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_RUBY_CAMERA_H__
|
4
|
+
#define __RAYS_RUBY_CAMERA_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rucy/rucy.h>
|
8
|
+
#include <rucy/class.h>
|
9
|
+
#include <rucy/extension.h>
|
10
|
+
#include <rays/camera.h>
|
11
|
+
|
12
|
+
|
13
|
+
namespace Rays
|
14
|
+
{
|
15
|
+
|
16
|
+
|
17
|
+
Rucy::Class camera_class ();
|
18
|
+
// class Rays::Camera
|
19
|
+
|
20
|
+
|
21
|
+
}// Rays
|
22
|
+
|
23
|
+
|
24
|
+
RUCY_DECLARE_VALUE_FROM_TO(Rays::Camera)
|
25
|
+
|
26
|
+
|
27
|
+
namespace Rucy
|
28
|
+
{
|
29
|
+
|
30
|
+
|
31
|
+
template <> inline Class
|
32
|
+
get_ruby_class<Rays::Camera> ()
|
33
|
+
{
|
34
|
+
return Rays::camera_class();
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
}// Rucy
|
39
|
+
|
40
|
+
|
41
|
+
#endif//EOH
|
data/include/rays/ruby/color.h
CHANGED
data/include/rays/ruby/font.h
CHANGED
data/include/rays/ruby/matrix.h
CHANGED
data/include/rays/ruby/point.h
CHANGED
@@ -0,0 +1,52 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_RUBY_POLYGON_H__
|
4
|
+
#define __RAYS_RUBY_POLYGON_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rucy/rucy.h>
|
8
|
+
#include <rucy/class.h>
|
9
|
+
#include <rucy/extension.h>
|
10
|
+
#include <rays/polygon.h>
|
11
|
+
|
12
|
+
|
13
|
+
namespace Rays
|
14
|
+
{
|
15
|
+
|
16
|
+
|
17
|
+
Rucy::Class polygon_class ();
|
18
|
+
// class Rays::Polygon
|
19
|
+
|
20
|
+
Rucy::Class polygon_line_class ();
|
21
|
+
// class Rays::Polygon::Line
|
22
|
+
|
23
|
+
|
24
|
+
}// Rays
|
25
|
+
|
26
|
+
|
27
|
+
RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Polygon)
|
28
|
+
|
29
|
+
RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Polygon::Line)
|
30
|
+
|
31
|
+
|
32
|
+
namespace Rucy
|
33
|
+
{
|
34
|
+
|
35
|
+
|
36
|
+
template <> inline Class
|
37
|
+
get_ruby_class<Rays::Polygon> ()
|
38
|
+
{
|
39
|
+
return Rays::polygon_class();
|
40
|
+
}
|
41
|
+
|
42
|
+
template <> inline Class
|
43
|
+
get_ruby_class<Rays::Polygon::Line> ()
|
44
|
+
{
|
45
|
+
return Rays::polygon_line_class();
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
}// Rucy
|
50
|
+
|
51
|
+
|
52
|
+
#endif//EOH
|
@@ -0,0 +1,41 @@
|
|
1
|
+
// -*- c++ -*-
|
2
|
+
#pragma once
|
3
|
+
#ifndef __RAYS_RUBY_POLYLINE_H__
|
4
|
+
#define __RAYS_RUBY_POLYLINE_H__
|
5
|
+
|
6
|
+
|
7
|
+
#include <rucy/rucy.h>
|
8
|
+
#include <rucy/class.h>
|
9
|
+
#include <rucy/extension.h>
|
10
|
+
#include <rays/polyline.h>
|
11
|
+
|
12
|
+
|
13
|
+
namespace Rays
|
14
|
+
{
|
15
|
+
|
16
|
+
|
17
|
+
Rucy::Class polyline_class ();
|
18
|
+
// class Rays::Polyline
|
19
|
+
|
20
|
+
|
21
|
+
}// Rays
|
22
|
+
|
23
|
+
|
24
|
+
RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Polyline)
|
25
|
+
|
26
|
+
|
27
|
+
namespace Rucy
|
28
|
+
{
|
29
|
+
|
30
|
+
|
31
|
+
template <> inline Class
|
32
|
+
get_ruby_class<Rays::Polyline> ()
|
33
|
+
{
|
34
|
+
return Rays::polyline_class();
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
}// Rucy
|
39
|
+
|
40
|
+
|
41
|
+
#endif//EOH
|
data/include/rays/ruby/rays.h
CHANGED
@@ -4,7 +4,10 @@
|
|
4
4
|
#define __RAYS_RUBY_RAYS_H__
|
5
5
|
|
6
6
|
|
7
|
+
#include <rucy/rucy.h>
|
7
8
|
#include <rucy/module.h>
|
9
|
+
#include <rucy/extension.h>
|
10
|
+
#include <rays/rays.h>
|
8
11
|
|
9
12
|
|
10
13
|
namespace Rays
|
@@ -18,4 +21,9 @@ namespace Rays
|
|
18
21
|
}// Rays
|
19
22
|
|
20
23
|
|
24
|
+
RUCY_DECLARE_CONVERT_TO(Rays::CapType)
|
25
|
+
|
26
|
+
RUCY_DECLARE_CONVERT_TO(Rays::JoinType)
|
27
|
+
|
28
|
+
|
21
29
|
#endif//EOH
|
data/include/rays/ruby/shader.h
CHANGED
data/include/rays/shader.h
CHANGED
@@ -5,13 +5,17 @@
|
|
5
5
|
|
6
6
|
|
7
7
|
#include <xot/pimpl.h>
|
8
|
-
#include
|
8
|
+
#include <rays/defs.h>
|
9
|
+
#include <rays/coord.h>
|
9
10
|
|
10
11
|
|
11
12
|
namespace Rays
|
12
13
|
{
|
13
14
|
|
14
15
|
|
16
|
+
class Image;
|
17
|
+
|
18
|
+
|
15
19
|
class Shader
|
16
20
|
{
|
17
21
|
|
@@ -19,25 +23,49 @@ namespace Rays
|
|
19
23
|
|
20
24
|
public:
|
21
25
|
|
22
|
-
Shader ();
|
23
|
-
|
24
|
-
Shader (const char* source);
|
26
|
+
Shader (const char* source = NULL);
|
25
27
|
|
26
28
|
~Shader ();
|
27
29
|
|
28
|
-
|
30
|
+
void set_uniform (const char* name, int arg1);
|
31
|
+
|
32
|
+
void set_uniform (const char* name, int arg1, int arg2);
|
33
|
+
|
34
|
+
void set_uniform (const char* name, int arg1, int arg2, int arg3);
|
35
|
+
|
36
|
+
void set_uniform (const char* name, int arg1, int arg2, int arg3, int arg4);
|
37
|
+
|
38
|
+
void set_uniform (const char* name, const int* args, size_t size);
|
39
|
+
|
40
|
+
void set_uniform (const char* name, float arg1);
|
29
41
|
|
30
|
-
|
42
|
+
void set_uniform (const char* name, float arg1, float arg2);
|
31
43
|
|
32
|
-
|
44
|
+
void set_uniform (const char* name, float arg1, float arg2, float arg3);
|
45
|
+
|
46
|
+
void set_uniform (const char* name, float arg1, float arg2, float arg3, float arg4);
|
47
|
+
|
48
|
+
void set_uniform (const char* name, const float* args, size_t size);
|
49
|
+
|
50
|
+
void set_uniform (const char* name, const Coord2& vec2);
|
51
|
+
|
52
|
+
void set_uniform (const char* name, const Coord3& vec3);
|
53
|
+
|
54
|
+
void set_uniform (const char* name, const Coord4& vec4);
|
55
|
+
|
56
|
+
void set_uniform (const char* name, const Image& texture);
|
33
57
|
|
34
58
|
operator bool () const;
|
35
59
|
|
36
60
|
bool operator ! () const;
|
37
61
|
|
62
|
+
friend bool operator == (const This& lhs, const This& rhs);
|
63
|
+
|
64
|
+
friend bool operator != (const This& lhs, const This& rhs);
|
65
|
+
|
38
66
|
struct Data;
|
39
67
|
|
40
|
-
Xot::
|
68
|
+
Xot::PSharedImpl<Data> self;
|
41
69
|
|
42
70
|
};// Shader
|
43
71
|
|
data/lib/rays.rb
CHANGED
@@ -8,9 +8,14 @@ require 'rays/point'
|
|
8
8
|
require 'rays/bounds'
|
9
9
|
require 'rays/color'
|
10
10
|
require 'rays/color_space'
|
11
|
+
require 'rays/matrix'
|
12
|
+
|
13
|
+
require 'rays/painter'
|
14
|
+
require 'rays/polyline'
|
15
|
+
require 'rays/polygon'
|
16
|
+
require 'rays/polygon_line'
|
11
17
|
require 'rays/bitmap'
|
12
|
-
require 'rays/texture'
|
13
18
|
require 'rays/image'
|
14
19
|
require 'rays/font'
|
15
20
|
require 'rays/shader'
|
16
|
-
require 'rays/
|
21
|
+
require 'rays/camera'
|
data/lib/rays/bitmap.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
require 'rays/ext'
|
5
|
-
require 'rays/color_space'
|
6
5
|
|
7
6
|
|
8
7
|
module Rays
|
@@ -12,10 +11,6 @@ module Rays
|
|
12
11
|
|
13
12
|
include Enumerable
|
14
13
|
|
15
|
-
def initialize (width, height, color_space = :RGBA)
|
16
|
-
setup width, height, ColorSpace.get_color_space(color_space)
|
17
|
-
end
|
18
|
-
|
19
14
|
def each ()
|
20
15
|
height.times do |y|
|
21
16
|
width.times do |x|
|
@@ -32,16 +27,6 @@ module Rays
|
|
32
27
|
map {|o| o}
|
33
28
|
end
|
34
29
|
|
35
|
-
def []= (x, y, *args)
|
36
|
-
args.flatten!
|
37
|
-
case args[0]
|
38
|
-
when Color
|
39
|
-
set_at x, y, args[0]
|
40
|
-
when Numeric
|
41
|
-
set_at x, y, *args
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
30
|
end# Bitmap
|
46
31
|
|
47
32
|
|
data/lib/rays/bounds.rb
CHANGED
@@ -11,40 +11,29 @@ module Rays
|
|
11
11
|
class Bounds
|
12
12
|
|
13
13
|
include Comparable
|
14
|
+
include Enumerable
|
14
15
|
|
15
|
-
alias w width
|
16
16
|
alias w= width=
|
17
|
+
alias w width
|
17
18
|
|
18
|
-
alias h height
|
19
19
|
alias h= height=
|
20
|
+
alias h height
|
20
21
|
|
21
|
-
alias d depth
|
22
22
|
alias d= depth=
|
23
|
+
alias d depth
|
23
24
|
|
24
|
-
def position= (*args)
|
25
|
-
set_position *Point.from(*args).to_a(3)
|
26
|
-
end
|
27
|
-
|
28
|
-
alias pos position
|
29
25
|
alias pos= position=
|
26
|
+
alias pos position
|
30
27
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
def center= (*args)
|
36
|
-
set_center *Point.from(*args).to_a(3)
|
37
|
-
end
|
38
|
-
|
39
|
-
alias left_top position
|
40
|
-
def right_top () position.move_by w - 1, 0 end
|
41
|
-
def left_bottom () position.move_by 0, h - 1 end
|
28
|
+
alias left_top position
|
29
|
+
def right_top () position .move_by w - 1, 0 end
|
30
|
+
def left_bottom () position .move_by 0, h - 1 end
|
42
31
|
def right_bottom () (position + size).move_by! -1, -1 end
|
43
32
|
|
44
|
-
def left_top= (*args) p = Point.
|
45
|
-
def right_top= (*args) p = Point.
|
46
|
-
def left_bottom= (*args) p = Point.
|
47
|
-
def right_bottom= (*args) p = Point.
|
33
|
+
def left_top= (*args) p = Point.new *args; self.left, self.top = p.x, p.y; left_top end
|
34
|
+
def right_top= (*args) p = Point.new *args; self.right, self.top = p.x, p.y; right_top end
|
35
|
+
def left_bottom= (*args) p = Point.new *args; self.left, self.bottom = p.x, p.y; left_bottom end
|
36
|
+
def right_bottom= (*args) p = Point.new *args; self.right, self.bottom = p.x, p.y; right_bottom end
|
48
37
|
|
49
38
|
alias lt left_top
|
50
39
|
alias lt= left_top=
|
@@ -75,7 +64,12 @@ module Rays
|
|
75
64
|
dup.inset_by! *args
|
76
65
|
end
|
77
66
|
|
67
|
+
def each (dimension = 2, &block)
|
68
|
+
to_a(dimension).each &block
|
69
|
+
end
|
70
|
+
|
78
71
|
def to_a (dimension = 2)
|
72
|
+
# TODO: return [lt, rb]
|
79
73
|
case dimension
|
80
74
|
when 1 then [x, w]
|
81
75
|
when 2 then [x, y, w, h]
|
data/lib/rays/camera.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require 'xot/block_util'
|
5
|
+
require 'rays/ext'
|
6
|
+
|
7
|
+
|
8
|
+
module Rays
|
9
|
+
|
10
|
+
|
11
|
+
class Camera
|
12
|
+
|
13
|
+
def initialize (*args, &block)
|
14
|
+
super *args
|
15
|
+
Xot::BlockUtil.instance_eval_or_block_call self, &block if block
|
16
|
+
end
|
17
|
+
|
18
|
+
end# Camera
|
19
|
+
|
20
|
+
|
21
|
+
end# Rays
|
data/lib/rays/color.rb
CHANGED
@@ -10,24 +10,19 @@ module Rays
|
|
10
10
|
class Color
|
11
11
|
|
12
12
|
include Comparable
|
13
|
+
include Enumerable
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
when Color then arg0
|
17
|
-
when Symbol then COLORS[arg0]
|
18
|
-
when /^\s*#[\da-fA-F]+\s*$/ then Color.new arg0
|
19
|
-
when String then COLORS[arg0.intern]
|
20
|
-
else Color.new *args
|
21
|
-
end
|
22
|
-
raise ArgumentError, "invalid argument '#{args}.'" unless c
|
23
|
-
c
|
24
|
-
end
|
15
|
+
alias r= red=
|
16
|
+
alias r red
|
25
17
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
18
|
+
alias g= green=
|
19
|
+
alias g green
|
20
|
+
|
21
|
+
alias b= blue=
|
22
|
+
alias b blue
|
23
|
+
|
24
|
+
alias a= alpha=
|
25
|
+
alias a alpha
|
31
26
|
|
32
27
|
def opaque? ()
|
33
28
|
alpha >= 1
|
@@ -42,12 +37,16 @@ module Rays
|
|
42
37
|
0 < a && a < 1
|
43
38
|
end
|
44
39
|
|
40
|
+
def each (&block)
|
41
|
+
to_a.each &block
|
42
|
+
end
|
43
|
+
|
45
44
|
def to_a ()
|
46
45
|
[red, green, blue, alpha]
|
47
46
|
end
|
48
47
|
|
49
48
|
def to_s ()
|
50
|
-
to_a.
|
49
|
+
to_a.to_s
|
51
50
|
end
|
52
51
|
|
53
52
|
def [] (index)
|
@@ -77,6 +76,10 @@ module Rays
|
|
77
76
|
alpha <=> o.alpha
|
78
77
|
end
|
79
78
|
|
79
|
+
def hash ()
|
80
|
+
red.hash + green.hash + blue.hash + alpha.hash
|
81
|
+
end
|
82
|
+
|
80
83
|
def eql? (o)
|
81
84
|
self == o
|
82
85
|
end
|
@@ -85,36 +88,6 @@ module Rays
|
|
85
88
|
"#<#{self.class.name} #{to_s}>"
|
86
89
|
end
|
87
90
|
|
88
|
-
COLORS = {
|
89
|
-
black: [0, 0, 0],
|
90
|
-
red: [1, 0, 0],
|
91
|
-
green: [0, 1, 0],
|
92
|
-
blue: [0, 0, 1],
|
93
|
-
yellow: [1, 1, 0],
|
94
|
-
cyan: [0, 1, 1],
|
95
|
-
magenta: [1, 0, 1],
|
96
|
-
white: [1, 1, 1],
|
97
|
-
gray: [0.5, 0.5, 0.5],
|
98
|
-
no: [0, 0],
|
99
|
-
none: [0, 0],
|
100
|
-
nil: [0, 0],
|
101
|
-
}.inject({}) {|h, (k, v)| h[k] = Color.new *v; h}
|
102
|
-
|
103
|
-
private
|
104
|
-
|
105
|
-
RE_RGBA = /^\s*##{'([\da-fA-F]{1})' * 4}?\s*$/
|
106
|
-
RE_RRGGBBAA = /^\s*##{'([\da-fA-F]{2})' * 4}?\s*$/
|
107
|
-
|
108
|
-
def parse (str)
|
109
|
-
case str
|
110
|
-
when RE_RGBA
|
111
|
-
[$1, $2, $3, $4 || 'f' ].map {|s| s.to_i(16) / 15.0}
|
112
|
-
when RE_RRGGBBAA
|
113
|
-
[$1, $2, $3, $4 || 'ff'].map {|s| s.to_i(16) / 255.0}
|
114
|
-
else raise ArgumentError, "can not parse '#{str}'."
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
91
|
end# Color
|
119
92
|
|
120
93
|
|