Class: Ray::Color

Inherits:
Object
  • Object
show all
Defined in:
ext/color.c,
lib/ray/color.rb,
ext/color.c

Overview

Represents a color, which does not rely on the pixel format of any surfaces.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(red, green, blue, alpha = 255) ⇒ Object

Creates a new color. All the parameters must be integers between 0 and 255. Alpha is the transparency (255: opaque, 0: invisible)



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'ext/color.c', line 42

VALUE ray_init_color(int argc, VALUE *argv, VALUE self) {
   VALUE r, g, b, a;
   rb_scan_args(argc, argv, "31", &r, &g, &b, &a);
   if (a == Qnil) a = INT2FIX(255);

   ray_color *ret = NULL;
   Data_Get_Struct(self, ray_color, ret);

   ret->r = NUM2INT(r);
   ret->g = NUM2INT(g);
   ret->b = NUM2INT(b);
   ret->a = NUM2INT(a);

   return Qnil;
}

Class Method Details

.blackObject



7
# File 'lib/ray/color.rb', line 7

def black;   new(0, 0,0);        end

.blueObject



6
# File 'lib/ray/color.rb', line 6

def blue;    new(0, 0, 255);     end

.cyanObject



11
# File 'lib/ray/color.rb', line 11

def cyan;    new(0, 255, 255);   end

.fuschiaObject



13
# File 'lib/ray/color.rb', line 13

def fuschia; new(255, 0, 255);   end

.grayObject



10
# File 'lib/ray/color.rb', line 10

def gray;    new(128, 128, 128); end

.greenObject



5
# File 'lib/ray/color.rb', line 5

def green;   new(0, 255, 0);     end

.noneObject



9
# File 'lib/ray/color.rb', line 9

def none;    new(0, 0, 0, 0);    end

.redObject



4
# File 'lib/ray/color.rb', line 4

def red;     new(255, 0, 0);     end

.whiteObject



8
# File 'lib/ray/color.rb', line 8

def white;   new(255, 255, 255); end

.yellowObject



12
# File 'lib/ray/color.rb', line 12

def yellow;  new(255, 255, 0);   end

Instance Method Details

#==(obj) ⇒ Object



20
21
22
23
# File 'lib/ray/color.rb', line 20

def ==(obj)
  return false unless obj.is_a? Color
  r == obj.r && g == obj.g && b == obj.b && a == obj.a
end

#aInteger Also known as: alpha

Returns alpha intensity.

Returns:

  • (Integer)

    alpha intensity



83
84
85
86
87
88
# File 'ext/color.c', line 83

VALUE ray_color_a(VALUE self) {
   ray_color *ret;
   Data_Get_Struct(self, ray_color, ret);

   return INT2FIX(ret->a);
}

#a=(val) ⇒ Object Also known as: alpha=

Sets the alpha intensity



118
119
120
121
122
123
124
# File 'ext/color.c', line 118

VALUE ray_color_set_a(VALUE self, VALUE val) {
   ray_color *ret;
   Data_Get_Struct(self, ray_color, ret);

   ret->a = NUM2INT(val);
   return val;
}

#bInteger Also known as: blue

Returns blue intensity.

Returns:

  • (Integer)

    blue intensity



75
76
77
78
79
80
# File 'ext/color.c', line 75

VALUE ray_color_b(VALUE self) {
   ray_color *ret;
   Data_Get_Struct(self, ray_color, ret);

   return INT2FIX(ret->b);
}

#b=(val) ⇒ Object Also known as: blue=

Sets the blue intensity



109
110
111
112
113
114
115
# File 'ext/color.c', line 109

VALUE ray_color_set_b(VALUE self, VALUE val) {
   ray_color *ret;
   Data_Get_Struct(self, ray_color, ret);

   ret->b = NUM2INT(val);
   return val;
}

#gInteger Also known as: green

Returns green intensity.

Returns:

  • (Integer)

    green intensity



67
68
69
70
71
72
# File 'ext/color.c', line 67

VALUE ray_color_g(VALUE self) {
   ray_color *ret;
   Data_Get_Struct(self, ray_color, ret);

   return INT2FIX(ret->g);
}

#g=(val) ⇒ Object Also known as: green=

Sets the green intensity



100
101
102
103
104
105
106
# File 'ext/color.c', line 100

VALUE ray_color_set_g(VALUE self, VALUE val) {
   ray_color *ret;
   Data_Get_Struct(self, ray_color, ret);

   ret->g = NUM2INT(val);
   return val;
}

#inspectObject



16
17
18
# File 'lib/ray/color.rb', line 16

def inspect
  "RGBA(#{r}, #{g}, #{b}, #{a})"
end

#rInteger Also known as: red

Returns red intensity.

Returns:

  • (Integer)

    red intensity



59
60
61
62
63
64
# File 'ext/color.c', line 59

VALUE ray_color_r(VALUE self) {
   ray_color *ret;
   Data_Get_Struct(self, ray_color, ret);

   return INT2FIX(ret->r);
}

#r=(val) ⇒ Object Also known as: red=

Sets the red intensity



91
92
93
94
95
96
97
# File 'ext/color.c', line 91

VALUE ray_color_set_r(VALUE self, VALUE val) {
   ray_color *ret;
   Data_Get_Struct(self, ray_color, ret);

   ret->r = NUM2INT(val);
   return val;
}

#to_colorObject



25
26
27
# File 'lib/ray/color.rb', line 25

def to_color
  self
end