parent
e4d1900965
commit
10b0e1811e
|
|
@ -53,5 +53,31 @@ module Squib
|
|||
end
|
||||
end
|
||||
|
||||
# Draw a triangle using the given coordinates
|
||||
#
|
||||
# @example
|
||||
# triangle :x1 => 0, :y1 => 0, :x2 => 50, :y2 => 50, :x3 => 0, :y3 => 50
|
||||
#
|
||||
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
||||
# @option opts x1 [Integer] (0) the x-coordinate to place
|
||||
# @option opts y1 [Integer] (0) the y-coordinate to place
|
||||
# @option opts x2 [Integer] (50) the x-coordinate to place
|
||||
# @option opts y2 [Integer] (50) the y-coordinate to place
|
||||
# @option opts x3 [Integer] (0) the x-coordinate to place
|
||||
# @option opts y3 [Integer] (50) the y-coordinate to place
|
||||
# @option opts fill_color [String] ('#0000') the color with which to fill the rectangle
|
||||
# @option opts stroke_color [String] (:black) the color with which to stroke the outside of the rectangle
|
||||
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke
|
||||
# @return [nil] intended to be void
|
||||
# @api public
|
||||
def triangle(opts = {})
|
||||
opts = needs(opts, [:range, :x1, :y1, :x2, :y2, :x3, :y3, :layout,
|
||||
:fill_color, :stroke_color, :stroke_width])
|
||||
opts[:range].each do |i|
|
||||
@cards[i].triangle(opts[:x1], opts[:y1], opts[:x2], opts[:y2],opts[:x3], opts[:y3],
|
||||
opts[:fill_color], opts[:stroke_color], opts[:stroke_width])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -13,6 +13,12 @@ module Squib
|
|||
:sheet => 0,
|
||||
:x => 0,
|
||||
:y => 0,
|
||||
:x1 => 100,
|
||||
:y1 => 100,
|
||||
:x2 => 150,
|
||||
:y2 => 150,
|
||||
:x3 => 100,
|
||||
:y3 => 150,
|
||||
:x_radius => 0,
|
||||
:y_radius => 0,
|
||||
:align => :left,
|
||||
|
|
|
|||
|
|
@ -28,5 +28,18 @@ module Squib
|
|||
cc.fill
|
||||
end
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def triangle(x1, y1, x2, y2, x3, y3, fill_color, stroke_color, stroke_width)
|
||||
cc = cairo_context
|
||||
cc.triangle(x1, y1, x2, y2, x3, y3)
|
||||
cc.set_source_color(stroke_color)
|
||||
cc.set_line_width(stroke_width)
|
||||
cc.stroke
|
||||
cc.triangle(x1, y1, x2, y2, x3, y3)
|
||||
cc.set_source_color(fill_color)
|
||||
cc.fill
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
require 'squib'
|
||||
|
||||
Squib::Deck.new do
|
||||
rect x: 300, y: 300, width: 400, height: 400,
|
||||
fill_color: :blue, stroke_color: :red, stroke_width: 50.0
|
||||
|
||||
circle x: 600, y: 600, radius: 75,
|
||||
fill_color: :gray, stroke_color: :green, stroke_width: 8.0
|
||||
|
||||
triangle x1: 50, y1: 50,
|
||||
x2: 150, y2: 150,
|
||||
x3: 75, y3: 250
|
||||
|
||||
save_png prefix: 'shape_'
|
||||
end
|
||||
Loading…
Reference in New Issue