Class: GrADS::Command::RGB
- Inherits:
-
Object
- Object
- GrADS::Command::RGB
- Defined in:
- lib/grads/command.rb
Constant Summary collapse
- @@number =
nil- @@table =
{}
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#b ⇒ Object
readonly
Returns the value of attribute b.
-
#g ⇒ Object
readonly
Returns the value of attribute g.
-
#r ⇒ Object
readonly
Returns the value of attribute r.
Class Method Summary collapse
Instance Method Summary collapse
- #%(alpha) ⇒ Object
- #*(scale) ⇒ Object
- #+(other) ⇒ Object
- #/(scale) ⇒ Object
-
#initialize(r, g, b, a = 255) ⇒ RGB
constructor
A new instance of RGB.
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(r, g, b, a = 255) ⇒ RGB
Returns a new instance of RGB.
1031 1032 1033 1034 1035 1036 |
# File 'lib/grads/command.rb', line 1031 def initialize (r, g, b, a=255) @r = r @g = g @b = b @a = a end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
1038 1039 1040 |
# File 'lib/grads/command.rb', line 1038 def a @a end |
#b ⇒ Object (readonly)
Returns the value of attribute b.
1038 1039 1040 |
# File 'lib/grads/command.rb', line 1038 def b @b end |
#g ⇒ Object (readonly)
Returns the value of attribute g.
1038 1039 1040 |
# File 'lib/grads/command.rb', line 1038 def g @g end |
#r ⇒ Object (readonly)
Returns the value of attribute r.
1038 1039 1040 |
# File 'lib/grads/command.rb', line 1038 def r @r end |
Class Method Details
.next_number ⇒ Object
1021 1022 1023 1024 1025 1026 1027 |
# File 'lib/grads/command.rb', line 1021 def self.next_number @@number += 1 if @@number > 2047 reset end return @@number end |
.reset ⇒ Object
1017 1018 1019 |
# File 'lib/grads/command.rb', line 1017 def self.reset @@number = 100 end |
Instance Method Details
#%(alpha) ⇒ Object
1048 1049 1050 1051 1052 1053 1054 1055 |
# File 'lib/grads/command.rb', line 1048 def % (alpha) if alpha >= 0 and alpha <= 1 a = (@a*alpha).to_i else raise "invalid alpha value" end return RGB.new(@r, @g, @b, a) end |
#*(scale) ⇒ Object
1057 1058 1059 1060 1061 1062 1063 |
# File 'lib/grads/command.rb', line 1057 def * (scale) if scale >= 0 and scale <= 1 return RGB.new((@r*scale).to_i, (@g*scale).to_i, (@b*scale).to_i, @a) else raise "invalid scale value" end end |
#+(other) ⇒ Object
1073 1074 1075 1076 1077 1078 1079 |
# File 'lib/grads/command.rb', line 1073 def + (other) r = [self.r, other.r].max g = [self.g, other.g].max b = [self.b, other.b].max a = [self.a, other.a].max return RGB.new(r,g,b,a) end |
#/(scale) ⇒ Object
1065 1066 1067 1068 1069 1070 1071 |
# File 'lib/grads/command.rb', line 1065 def / (scale) if scale >= 1 return RGB.new((@r/scale).to_i, (@g/scale).to_i, (@b/scale).to_i, @a) else raise "invalid scale value" end end |
#to_a ⇒ Object
1044 1045 1046 |
# File 'lib/grads/command.rb', line 1044 def to_a return [@r, @g, @b, @a] end |
#to_s ⇒ Object
1040 1041 1042 |
# File 'lib/grads/command.rb', line 1040 def to_s return format("%i %i %i %i", @r, @g, @b, @a) end |