Star feature works, testing is still pending
parent
14e04a89c7
commit
4b63716dfc
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue