Class: Magick::HatchFill

Inherits:
Object
  • Object
show all
Defined in:
lib/RMagick.rb

Overview

Example fill class. Fills the image with the specified background color, then crosshatches with the specified crosshatch color. See Magick::Draw examples.

Instance Method Summary collapse

Constructor Details

#initialize(bgcolor, hatchcolor = "white", dist = 10) ⇒ HatchFill

Returns a new instance of HatchFill.



1612
1613
1614
1615
1616
# File 'lib/RMagick.rb', line 1612

def initialize(bgcolor, hatchcolor="white", dist=10)
   @bgcolor = bgcolor
   @hatchpixel = Pixel.from_color(hatchcolor)
   @dist = dist
end

Instance Method Details

#fill(img) ⇒ Object

required



1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
# File 'lib/RMagick.rb', line 1618

def fill(img)                # required
   img.background_color = @bgcolor
   img.erase!                # sets image to background color
   pixels = Array.new([img.rows, img.columns].max, @hatchpixel)
   @dist.step((img.columns-1)/@dist*@dist, @dist) { |x|
      img.store_pixels(x,0,1,img.rows,pixels)
   }
   @dist.step((img.rows-1)/@dist*@dist, @dist) { |y|
      img.store_pixels(0,y,img.columns,1,pixels)
   }
end