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.
Files changed (168) hide show
  1. checksums.yaml +5 -5
  2. data/.doc/ext/rays/bitmap.cpp +22 -76
  3. data/.doc/ext/rays/bounds.cpp +95 -125
  4. data/.doc/ext/rays/camera.cpp +88 -0
  5. data/.doc/ext/rays/color.cpp +223 -45
  6. data/.doc/ext/rays/color_space.cpp +146 -46
  7. data/.doc/ext/rays/defs.cpp +183 -0
  8. data/.doc/ext/rays/font.cpp +69 -21
  9. data/.doc/ext/rays/image.cpp +26 -37
  10. data/.doc/ext/rays/matrix.cpp +186 -29
  11. data/.doc/ext/rays/native.cpp +14 -8
  12. data/.doc/ext/rays/noise.cpp +53 -0
  13. data/.doc/ext/rays/painter.cpp +187 -292
  14. data/.doc/ext/rays/point.cpp +96 -77
  15. data/.doc/ext/rays/polygon.cpp +313 -0
  16. data/.doc/ext/rays/polygon_line.cpp +96 -0
  17. data/.doc/ext/rays/polyline.cpp +167 -0
  18. data/.doc/ext/rays/rays.cpp +103 -12
  19. data/.doc/ext/rays/shader.cpp +83 -9
  20. data/LICENSE +21 -0
  21. data/README.md +1 -1
  22. data/Rakefile +24 -9
  23. data/VERSION +1 -1
  24. data/ext/rays/bitmap.cpp +22 -80
  25. data/ext/rays/bounds.cpp +100 -128
  26. data/ext/rays/camera.cpp +94 -0
  27. data/ext/rays/color.cpp +231 -51
  28. data/ext/rays/color_space.cpp +149 -47
  29. data/ext/rays/defs.cpp +183 -0
  30. data/ext/rays/defs.h +26 -2
  31. data/ext/rays/extconf.rb +2 -3
  32. data/ext/rays/font.cpp +74 -24
  33. data/ext/rays/image.cpp +28 -40
  34. data/ext/rays/matrix.cpp +198 -30
  35. data/ext/rays/native.cpp +14 -8
  36. data/ext/rays/noise.cpp +55 -0
  37. data/ext/rays/painter.cpp +203 -298
  38. data/ext/rays/point.cpp +105 -81
  39. data/ext/rays/polygon.cpp +329 -0
  40. data/ext/rays/polygon_line.cpp +99 -0
  41. data/ext/rays/polyline.cpp +176 -0
  42. data/ext/rays/rays.cpp +103 -13
  43. data/ext/rays/shader.cpp +84 -9
  44. data/include/rays.h +10 -2
  45. data/include/rays/bitmap.h +14 -26
  46. data/include/rays/bounds.h +21 -4
  47. data/include/rays/camera.h +49 -0
  48. data/include/rays/color.h +25 -14
  49. data/include/rays/color_space.h +15 -10
  50. data/include/rays/coord.h +114 -0
  51. data/include/rays/debug.h +22 -0
  52. data/include/rays/defs.h +36 -0
  53. data/include/rays/exception.h +6 -2
  54. data/include/rays/font.h +4 -4
  55. data/include/rays/image.h +12 -18
  56. data/include/rays/matrix.h +50 -24
  57. data/include/rays/noise.h +42 -0
  58. data/include/rays/opengl.h +2 -50
  59. data/include/rays/painter.h +89 -93
  60. data/include/rays/point.h +44 -51
  61. data/include/rays/polygon.h +198 -0
  62. data/include/rays/polyline.h +71 -0
  63. data/include/rays/rays.h +3 -0
  64. data/include/rays/ruby.h +7 -1
  65. data/include/rays/ruby/bounds.h +1 -1
  66. data/include/rays/ruby/camera.h +41 -0
  67. data/include/rays/ruby/color.h +1 -1
  68. data/include/rays/ruby/color_space.h +1 -1
  69. data/include/rays/ruby/font.h +1 -1
  70. data/include/rays/ruby/matrix.h +1 -1
  71. data/include/rays/ruby/point.h +1 -1
  72. data/include/rays/ruby/polygon.h +52 -0
  73. data/include/rays/ruby/polyline.h +41 -0
  74. data/include/rays/ruby/rays.h +8 -0
  75. data/include/rays/ruby/shader.h +1 -1
  76. data/include/rays/shader.h +36 -8
  77. data/lib/rays.rb +7 -2
  78. data/lib/rays/bitmap.rb +0 -15
  79. data/lib/rays/bounds.rb +17 -23
  80. data/lib/rays/camera.rb +21 -0
  81. data/lib/rays/color.rb +20 -47
  82. data/lib/rays/color_space.rb +13 -13
  83. data/lib/rays/image.rb +3 -7
  84. data/lib/rays/matrix.rb +28 -0
  85. data/lib/rays/module.rb +4 -19
  86. data/lib/rays/painter.rb +78 -93
  87. data/lib/rays/point.rb +13 -21
  88. data/lib/rays/polygon.rb +58 -0
  89. data/lib/rays/polygon_line.rb +36 -0
  90. data/lib/rays/polyline.rb +32 -0
  91. data/lib/rays/shader.rb +20 -1
  92. data/rays.gemspec +5 -7
  93. data/src/bitmap.h +36 -0
  94. data/src/bounds.cpp +74 -11
  95. data/src/color.cpp +58 -23
  96. data/src/color_space.cpp +52 -34
  97. data/src/color_space.h +22 -0
  98. data/src/coord.cpp +170 -0
  99. data/src/coord.h +35 -0
  100. data/src/font.cpp +118 -0
  101. data/src/font.h +64 -0
  102. data/src/frame_buffer.cpp +37 -71
  103. data/src/frame_buffer.h +4 -4
  104. data/src/image.cpp +172 -98
  105. data/src/image.h +25 -0
  106. data/src/ios/bitmap.h +21 -0
  107. data/src/ios/bitmap.mm +129 -110
  108. data/src/ios/camera.mm +236 -0
  109. data/src/ios/font.mm +50 -62
  110. data/src/ios/helper.h +2 -2
  111. data/src/ios/opengl.mm +19 -4
  112. data/src/ios/rays.mm +3 -0
  113. data/src/matrix.cpp +111 -26
  114. data/src/matrix.h +30 -0
  115. data/src/noise.cpp +74 -0
  116. data/src/opengl.cpp +9 -27
  117. data/src/opengl.h +37 -0
  118. data/src/osx/bitmap.h +21 -0
  119. data/src/osx/bitmap.mm +129 -110
  120. data/src/osx/camera.mm +236 -0
  121. data/src/osx/font.mm +49 -62
  122. data/src/osx/helper.h +2 -2
  123. data/src/osx/opengl.mm +19 -83
  124. data/src/osx/rays.mm +3 -0
  125. data/src/painter.cpp +845 -671
  126. data/src/painter.h +24 -0
  127. data/src/point.cpp +140 -119
  128. data/src/polygon.cpp +1266 -0
  129. data/src/polygon.h +32 -0
  130. data/src/polyline.cpp +160 -0
  131. data/src/polyline.h +69 -0
  132. data/src/render_buffer.cpp +11 -4
  133. data/src/render_buffer.h +2 -2
  134. data/src/shader.cpp +163 -106
  135. data/src/shader.h +38 -0
  136. data/src/shader_program.cpp +533 -0
  137. data/src/{program.h → shader_program.h} +28 -16
  138. data/src/shader_source.cpp +140 -0
  139. data/src/shader_source.h +52 -0
  140. data/src/texture.cpp +136 -160
  141. data/src/texture.h +65 -0
  142. data/src/win32/bitmap.cpp +62 -52
  143. data/src/win32/font.cpp +11 -13
  144. data/src/win32/font.h +24 -0
  145. data/src/win32/gdi.h +6 -6
  146. data/test/helper.rb +0 -3
  147. data/test/test_bitmap.rb +31 -7
  148. data/test/test_bounds.rb +36 -0
  149. data/test/test_color.rb +59 -19
  150. data/test/test_color_space.rb +95 -0
  151. data/test/test_font.rb +5 -0
  152. data/test/test_image.rb +24 -20
  153. data/test/test_matrix.rb +106 -0
  154. data/test/test_painter.rb +157 -51
  155. data/test/test_painter_shape.rb +102 -0
  156. data/test/test_point.rb +29 -0
  157. data/test/test_polygon.rb +234 -0
  158. data/test/test_polygon_line.rb +167 -0
  159. data/test/test_polyline.rb +171 -0
  160. data/test/test_shader.rb +9 -9
  161. metadata +102 -70
  162. data/.doc/ext/rays/texture.cpp +0 -138
  163. data/ext/rays/texture.cpp +0 -149
  164. data/include/rays/ruby/texture.h +0 -41
  165. data/include/rays/texture.h +0 -71
  166. data/lib/rays/texture.rb +0 -24
  167. data/src/program.cpp +0 -648
  168. data/test/test_texture.rb +0 -27
@@ -23,7 +23,7 @@ namespace Rays
23
23
  }// Rays
24
24
 
25
25
 
26
- RUCY_DECLARE_VALUE_FROM_TO(Rays::Bounds)
26
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Bounds)
27
27
 
28
28
 
29
29
  namespace Rucy
@@ -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
@@ -22,7 +22,7 @@ namespace Rays
22
22
  }// Rays
23
23
 
24
24
 
25
- RUCY_DECLARE_VALUE_FROM_TO(Rays::Color)
25
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Color)
26
26
 
27
27
 
28
28
  namespace Rucy
@@ -21,7 +21,7 @@ namespace Rays
21
21
  }// Rays
22
22
 
23
23
 
24
- RUCY_DECLARE_VALUE_FROM_TO(Rays::ColorSpace)
24
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::ColorSpace)
25
25
 
26
26
 
27
27
  namespace Rucy
@@ -21,7 +21,7 @@ namespace Rays
21
21
  }// Rays
22
22
 
23
23
 
24
- RUCY_DECLARE_VALUE_FROM_TO(Rays::Font)
24
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Font)
25
25
 
26
26
 
27
27
  namespace Rucy
@@ -21,7 +21,7 @@ namespace Rays
21
21
  }// Rays
22
22
 
23
23
 
24
- RUCY_DECLARE_VALUE_FROM_TO(Rays::Matrix)
24
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Matrix)
25
25
 
26
26
 
27
27
  namespace Rucy
@@ -22,7 +22,7 @@ namespace Rays
22
22
  }// Rays
23
23
 
24
24
 
25
- RUCY_DECLARE_VALUE_FROM_TO(Rays::Point)
25
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Point)
26
26
 
27
27
 
28
28
  namespace Rucy
@@ -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
@@ -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
@@ -21,7 +21,7 @@ namespace Rays
21
21
  }// Rays
22
22
 
23
23
 
24
- RUCY_DECLARE_VALUE_FROM_TO(Rays::Shader)
24
+ RUCY_DECLARE_VALUE_OR_ARRAY_FROM_TO(Rays::Shader)
25
25
 
26
26
 
27
27
  namespace Rucy
@@ -5,13 +5,17 @@
5
5
 
6
6
 
7
7
  #include <xot/pimpl.h>
8
- #include "rays/opengl.h"
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
- GLuint id () const;
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
- bool operator == (const Shader& rhs) const;
42
+ void set_uniform (const char* name, float arg1, float arg2);
31
43
 
32
- bool operator != (const Shader& rhs) const;
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::PImpl<Data, true> self;
68
+ Xot::PSharedImpl<Data> self;
41
69
 
42
70
  };// Shader
43
71
 
@@ -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/painter'
21
+ require 'rays/camera'
@@ -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
 
@@ -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
- def size= (*args)
32
- set_size *Point.from(*args).to_a(3)
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.from *args; self.left, self.top = p.x, p.y; left_top end
45
- def right_top= (*args) p = Point.from *args; self.right, self.top = p.x, p.y; right_top end
46
- def left_bottom= (*args) p = Point.from *args; self.left, self.bottom = p.x, p.y; left_bottom end
47
- def right_bottom= (*args) p = Point.from *args; self.right, self.bottom = p.x, p.y; right_bottom end
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]
@@ -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
@@ -10,24 +10,19 @@ module Rays
10
10
  class Color
11
11
 
12
12
  include Comparable
13
+ include Enumerable
13
14
 
14
- def self.color (*args)
15
- c = case arg0 = args[0]
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
- def initialize (*args)
27
- arg0 = args[0]
28
- args = parse arg0 if arg0 && arg0.kind_of?(String)
29
- setup *args
30
- end
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.map {|o| o.to_s}
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