lib/chunky_png/canvas/drawing.rb in chunky_png-1.0.0.rc1 vs lib/chunky_png/canvas/drawing.rb in chunky_png-1.0.0.rc2
- old
+ new
@@ -20,11 +20,12 @@
# @param [ChunkyPNG::Point, ...] point The point on the canvas to blend.
# @param [Integer] color The foreground color to blend with
def compose_pixel(*args)
point = args.length == 2 ? ChunkyPNG::Point(args.first) : ChunkyPNG::Point(args[0], args[1])
return unless include?(point)
- set_pixel(point.x, point.y, ChunkyPNG::Color.compose(args.last, get_pixel(point.x, point.y)))
+ color = ChunkyPNG::Color(args.last)
+ set_pixel(point.x, point.y, ChunkyPNG::Color.compose(color, get_pixel(point.x, point.y)))
end
# Draws an anti-aliased line using Xiaolin Wu's algorithm.
#
# @param [Integer] x0 The x-coordinate of the first control point.
@@ -34,10 +35,13 @@
# @param [Integer] stroke_color The color to use for this line.
# @param [true, false] inclusive Whether to draw the last pixel.
# Set to false when drawing multiplelines in a path.
# @return [ChunkyPNG::Canvas] Itself, with the line drawn.
def line_xiaolin_wu(x0, y0, x1, y1, stroke_color, inclusive = true)
+
+ stroke_color = ChunkyPNG::Color(stroke_color)
+
dx = x1 - x0
sx = dx < 0 ? -1 : 1
dx *= sx
dy = y1 - y0
sy = dy < 0 ? -1 : 1
@@ -101,12 +105,15 @@
# @param [Integer] fill_color The fill color to use for this polygon.
# @return [ChunkyPNG::Canvas] Itself, with the polygon drawn.
def polygon(path, stroke_color = ChunkyPNG::Color::BLACK, fill_color = ChunkyPNG::Color::TRANSPARENT)
vector = ChunkyPNG::Vector(*path)
- raise ChunkyPNG::ExpectationFailed, "A polygon requires at least 3 points" if path.length < 3
+ raise ArgumentError, "A polygon requires at least 3 points" if path.length < 3
+ stroke_color = ChunkyPNG::Color(stroke_color)
+ fill_color = ChunkyPNG::Color(fill_color)
+
# Fill
unless fill_color == ChunkyPNG::Color::TRANSPARENT
vector.y_range.each do |y|
intersections = []
vector.edges.each do |p1, p2|
@@ -141,10 +148,13 @@
# @param [Integer] stroke_color The line color to use for this rectangle.
# @param [Integer] fill_color The fill color to use for this rectangle.
# @return [ChunkyPNG::Canvas] Itself, with the rectangle drawn.
def rect(x0, y0, x1, y1, stroke_color = ChunkyPNG::Color::BLACK, fill_color = ChunkyPNG::Color::TRANSPARENT)
+ stroke_color = ChunkyPNG::Color(stroke_color)
+ fill_color = ChunkyPNG::Color(fill_color)
+
# Fill
unless fill_color == ChunkyPNG::Color::TRANSPARENT
[x0, x1].min.upto([x0, x1].max) do |x|
[y0, y1].min.upto([y0, y1].max) do |y|
compose_pixel(x, y, fill_color)
@@ -168,9 +178,12 @@
# @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.
def circle(x0, y0, radius, stroke_color = ChunkyPNG::Color::BLACK, fill_color = ChunkyPNG::Color::TRANSPARENT)
+
+ stroke_color = ChunkyPNG::Color(stroke_color)
+ fill_color = ChunkyPNG::Color(fill_color)
f = 1 - radius
ddF_x = 1
ddF_y = -2 * radius
x = 0