Star feature works, testing is still pending
parent
14e04a89c7
commit
4b63716dfc
|
|
@ -102,10 +102,13 @@ module Squib
|
||||||
:font_size => :font_size,
|
:font_size => :font_size,
|
||||||
:height => :height,
|
:height => :height,
|
||||||
:hint => :hint,
|
:hint => :hint,
|
||||||
|
:inner_radius => :inner_radius,
|
||||||
:justify => :justify,
|
:justify => :justify,
|
||||||
:layout => :layout,
|
:layout => :layout,
|
||||||
:markup => :markup,
|
:markup => :markup,
|
||||||
:mask => :mask,
|
:mask => :mask,
|
||||||
|
:n => :n,
|
||||||
|
:outer_radius => :outer_radius,
|
||||||
:quotes => :quotes,
|
:quotes => :quotes,
|
||||||
:rect_radius => :radius,
|
:rect_radius => :radius,
|
||||||
:spacing => :spacing,
|
:spacing => :spacing,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ module Squib
|
||||||
:set_source, :scale, :render_rsvg_handle, :circle, :triangle, :line_to,
|
:set_source, :scale, :render_rsvg_handle, :circle, :triangle, :line_to,
|
||||||
:operator=, :show_page, :clip, :transform, :mask, :create_pango_layout,
|
:operator=, :show_page, :clip, :transform, :mask, :create_pango_layout,
|
||||||
:antialias=, :curve_to, :matrix, :matrix=, :identity_matrix, :pango_layout_path,
|
:antialias=, :curve_to, :matrix, :matrix=, :identity_matrix, :pango_layout_path,
|
||||||
:stroke_preserve, :target
|
:stroke_preserve, :target, :new_path, :fill_preserve
|
||||||
|
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
# @api private
|
# @api private
|
||||||
|
|
|
||||||
|
|
@ -106,21 +106,22 @@ module Squib
|
||||||
# @api private
|
# @api private
|
||||||
def star(x, y, n, angle, inner_radius, outer_radius, fill_color, stroke_color, stroke_width)
|
def star(x, y, n, angle, inner_radius, outer_radius, fill_color, stroke_color, stroke_width)
|
||||||
use_cairo do |cc|
|
use_cairo do |cc|
|
||||||
|
cc.new_path
|
||||||
cc.translate(x, y)
|
cc.translate(x, y)
|
||||||
cc.rotate(angle)
|
cc.rotate(angle)
|
||||||
cc.translate(-x, -y)
|
cc.translate(-x, -y)
|
||||||
|
cc.move_to(x + outer_radius, y) #i = 0, so
|
||||||
# coords = []
|
theta = Math::PI / n.to_f # i.e. (2*pi) / (2*n)
|
||||||
# coords << [x, y - outer_radius]
|
0.upto(2 * n) do |i|
|
||||||
# coords << [x, y - outer_radius]
|
radius = i.even? ? outer_radius : inner_radius
|
||||||
# cc.move_to(*coords.first)
|
cc.line_to(x + radius * Math::cos(i * theta),
|
||||||
# cc.line_to(*coords[1..-1])
|
y + radius * Math::sin(i * theta))
|
||||||
|
end
|
||||||
cc.set_source_squibcolor(stroke_color)
|
cc.set_source_squibcolor(stroke_color)
|
||||||
cc.set_line_width(stroke_width)
|
cc.set_line_width(stroke_width)
|
||||||
cc.stroke_preserve
|
cc.fill_preserve
|
||||||
cc.set_source_squibcolor(fill_color)
|
cc.set_source_squibcolor(fill_color)
|
||||||
cc.fill
|
cc.stroke
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ Squib::Deck.new do
|
||||||
stroke_width: 5.0, stroke_color: :cyan,
|
stroke_width: 5.0, stroke_color: :cyan,
|
||||||
fill_color: :burgundy
|
fill_color: :burgundy
|
||||||
|
|
||||||
star x: 50, y: 1000, n: 5, inner_radius: 50, outer_radius: 100,
|
star x: 300, y: 1000, n: 5, inner_radius: 10, outer_radius: 25,
|
||||||
fill_color: :burgundy, stroke_color: :cyan, stroke_width: 8
|
fill_color: :burgundy, stroke_color: :cyan, stroke_width: 1
|
||||||
|
|
||||||
save_png prefix: 'shape_'
|
save_png prefix: 'shape_'
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue