diff --git a/lib/squib/constants.rb b/lib/squib/constants.rb index 924376e..780ab4e 100644 --- a/lib/squib/constants.rb +++ b/lib/squib/constants.rb @@ -102,10 +102,13 @@ module Squib :font_size => :font_size, :height => :height, :hint => :hint, + :inner_radius => :inner_radius, :justify => :justify, :layout => :layout, :markup => :markup, :mask => :mask, + :n => :n, + :outer_radius => :outer_radius, :quotes => :quotes, :rect_radius => :radius, :spacing => :spacing, diff --git a/lib/squib/graphics/cairo_context_wrapper.rb b/lib/squib/graphics/cairo_context_wrapper.rb index d53782b..938cc0c 100644 --- a/lib/squib/graphics/cairo_context_wrapper.rb +++ b/lib/squib/graphics/cairo_context_wrapper.rb @@ -23,7 +23,7 @@ module Squib :set_source, :scale, :render_rsvg_handle, :circle, :triangle, :line_to, :operator=, :show_page, :clip, :transform, :mask, :create_pango_layout, :antialias=, :curve_to, :matrix, :matrix=, :identity_matrix, :pango_layout_path, - :stroke_preserve, :target + :stroke_preserve, :target, :new_path, :fill_preserve # :nodoc: # @api private diff --git a/lib/squib/graphics/shapes.rb b/lib/squib/graphics/shapes.rb index 1f76734..35b320b 100644 --- a/lib/squib/graphics/shapes.rb +++ b/lib/squib/graphics/shapes.rb @@ -106,21 +106,22 @@ module Squib # @api private def star(x, y, n, angle, inner_radius, outer_radius, fill_color, stroke_color, stroke_width) use_cairo do |cc| + cc.new_path cc.translate(x, y) cc.rotate(angle) cc.translate(-x, -y) - - # coords = [] - # coords << [x, y - outer_radius] - # coords << [x, y - outer_radius] - # cc.move_to(*coords.first) - # cc.line_to(*coords[1..-1]) - + cc.move_to(x + outer_radius, y) #i = 0, so + theta = Math::PI / n.to_f # i.e. (2*pi) / (2*n) + 0.upto(2 * n) do |i| + radius = i.even? ? outer_radius : inner_radius + cc.line_to(x + radius * Math::cos(i * theta), + y + radius * Math::sin(i * theta)) + end cc.set_source_squibcolor(stroke_color) cc.set_line_width(stroke_width) - cc.stroke_preserve + cc.fill_preserve cc.set_source_squibcolor(fill_color) - cc.fill + cc.stroke end end diff --git a/samples/draw_shapes.rb b/samples/draw_shapes.rb index 09688e4..4f01181 100644 --- a/samples/draw_shapes.rb +++ b/samples/draw_shapes.rb @@ -25,8 +25,8 @@ Squib::Deck.new do stroke_width: 5.0, stroke_color: :cyan, fill_color: :burgundy - star x: 50, y: 1000, n: 5, inner_radius: 50, outer_radius: 100, - fill_color: :burgundy, stroke_color: :cyan, stroke_width: 8 + star x: 300, y: 1000, n: 5, inner_radius: 10, outer_radius: 25, + fill_color: :burgundy, stroke_color: :cyan, stroke_width: 1 save_png prefix: 'shape_' end