Class: Magick::GradientFill
- Inherits:
-
Object
- Object
- Magick::GradientFill
- Defined in:
- ext/RMagick/rmmain.c
Instance Method Summary collapse
-
#fill(image_obj) ⇒ Object
Call GradientFill with the start and stop colors specified when this fill object was created.
-
#initialize(x1, y1, x2, y2, start_color, stop_color) ⇒ Object
constructor
Store the vector points and the start and stop colors.
Constructor Details
#initialize(x1, y1, x2, y2, start_color, stop_color) ⇒ Object
Store the vector points and the start and stop colors.
Ruby usage:
- @verbatim GradientFill#initialize(x1,y1,x2,y2,start_color,stop_color) @endverbatim
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'ext/RMagick/rmfill.c', line 76
VALUE
GradientFill_initialize(
VALUE self,
VALUE x1,
VALUE y1,
VALUE x2,
VALUE y2,
VALUE start_color,
VALUE stop_color)
{
rm_GradientFill *fill;
Data_Get_Struct(self, rm_GradientFill, fill);
fill->x1 = NUM2DBL(x1);
fill->y1 = NUM2DBL(y1);
fill->x2 = NUM2DBL(x2);
fill->y2 = NUM2DBL(y2);
Color_to_PixelColor(&fill->start_color, start_color);
Color_to_PixelColor(&fill->stop_color, stop_color);
return self;
}
|
Instance Method Details
#fill(image_obj) ⇒ Object
Call GradientFill with the start and stop colors specified when this fill object was created.
Ruby usage:
- @verbatim GradientFill#fill(image) @endverbatim
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'ext/RMagick/rmfill.c', line 508
VALUE
GradientFill_fill(VALUE self, VALUE image_obj)
{
rm_GradientFill *fill;
Image *image;
PixelColor start_color, stop_color;
double x1, y1, x2, y2; // points on the line
Data_Get_Struct(self, rm_GradientFill, fill);
image = rm_check_destroyed(image_obj);
x1 = fill->x1;
y1 = fill->y1;
x2 = fill->x2;
y2 = fill->y2;
start_color = fill->start_color;
stop_color = fill->stop_color;
if (fabs(x2-x1) < 0.5) // vertical?
{
// If the x1,y1 and x2,y2 points are essentially the same
if (fabs(y2-y1) < 0.5)
{
point_fill(image, x1, y1, &start_color, &stop_color);
}
// A vertical line is a special case.
else
{
vertical_fill(image, x1, &start_color, &stop_color);
}
}
// A horizontal line is a special case.
else if (fabs(y2-y1) < 0.5)
{
horizontal_fill(image, y1, &start_color, &stop_color);
}
// This is the general case - a diagonal line. If the line is more horizontal
// than vertical, use the top and bottom of the image as the ends of the
// gradient, otherwise use the sides of the image.
else
{
double m = ((double)(y2 - y1))/((double)(x2 - x1));
double diagonal = ((double)image->rows)/image->columns;
if (fabs(m) <= diagonal)
{
v_diagonal_fill(image, x1, y1, x2, y2, &start_color, &stop_color);
}
else
{
h_diagonal_fill(image, x1, y1, x2, y2, &start_color, &stop_color);
}
}
return self;
}
|