module ChunkyPNG::Canvas::Drawing
def circle(x0, y0, radius,
-
(ChunkyPNG::Canvas)
- Itself, with the circle drawn.
Parameters:
-
fill_color
(Integer
) -- The color to use that fills the circle. -
stroke_color
(Integer
) -- The color to use for the line. -
radius
(Integer
) -- The radius of the circle from the center point. -
y0
(Integer
) -- The y-coordinate of the center of the circle. -
x0
(Integer
) -- The x-coordinate of the center of the circle.
def circle(x0, y0, radius, stroke_color = ChunkyPNG::Color::BLACK, fill_color = ChunkyPNG::Color::TRANSPARENT) stroke_color = ChunkyPNG::Color.parse(stroke_color) fill_color = ChunkyPNG::Color.parse(fill_color) f = 1 - radius ddF_x = 1 ddF_y = -2 * radius x = 0 y = radius compose_pixel(x0, y0 + radius, stroke_color) compose_pixel(x0, y0 - radius, stroke_color) compose_pixel(x0 + radius, y0, stroke_color) compose_pixel(x0 - radius, y0, stroke_color) lines = [radius - 1] unless fill_color == ChunkyPNG::Color::TRANSPARENT while x < y if f >= 0 y -= 1 ddF_y += 2 f += ddF_y end x += 1 ddF_x += 2 f += ddF_x unless fill_color == ChunkyPNG::Color::TRANSPARENT lines[y] = lines[y] ? [lines[y], x - 1].min : x - 1 lines[x] = lines[x] ? [lines[x], y - 1].min : y - 1 end compose_pixel(x0 + x, y0 + y, stroke_color) compose_pixel(x0 - x, y0 + y, stroke_color) compose_pixel(x0 + x, y0 - y, stroke_color) compose_pixel(x0 - x, y0 - y, stroke_color) unless x == y compose_pixel(x0 + y, y0 + x, stroke_color) compose_pixel(x0 - y, y0 + x, stroke_color) compose_pixel(x0 + y, y0 - x, stroke_color) compose_pixel(x0 - y, y0 - x, stroke_color) end end unless fill_color == ChunkyPNG::Color::TRANSPARENT lines.each_with_index do |length, y_offset| if length > 0 line(x0 - length, y0 - y_offset, x0 + length, y0 - y_offset, fill_color) end if length > 0 && y_offset > 0 line(x0 - length, y0 + y_offset, x0 + length, y0 + y_offset, fill_color) end end end self end