lib/chunky_png/canvas/drawing.rb
# Draws a circle on the canvas.
#
# @param [Integer] x0 The x-coordinate of the center of the circle.
# @param [Integer] y0 The y-coordinate of the center of the circle.
# @param [Integer] radius The radius of the circle from the center point.
# @param [Integer] stroke_color The color to use for the line.
# @param [Integer] fill_color The color to use that fills the circle.
# @return [ChunkyPNG::Canvas] Itself, with the circle drawn.
Draws a circle on the canvas.
Draws a circle on the canvas .
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
        dd_f_x = 1
        dd_f_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
            dd_f_y += 2
            f += dd_f_y
          end
          x += 1
          dd_f_x += 2
          f += dd_f_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
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 dd_f_x = 1 dd_f_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 dd_f_y += 2 f += dd_f_y end x += 1 dd_f_x += 2 f += dd_f_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
Draws a circle on the canvas.
Draws a circle on the canvas .
Itself, with the circle drawn.
Itself with the circle drawn .
ChunkyPNG::Canvas
x0
<not_specific>
y0
<not_specific>
radius
<not_specific>
stroke_color
<not_specific>
fill_color
<not_specific>
<not_specific>
fill_color The color to use that fills the circle.
fill_color The color to use that fills the circle .