Browse Source

Started the star feature

Contributes to #72

[skip ci]
dev
Andy Meneely 11 years ago
parent
commit
14e04a89c7
  1. 27
      lib/squib/api/shapes.rb
  2. 3
      lib/squib/constants.rb
  3. 22
      lib/squib/graphics/shapes.rb
  4. 3
      samples/draw_shapes.rb
  5. 2
      squib.sublime-project

27
lib/squib/api/shapes.rb

@ -154,6 +154,7 @@ module Squib
# @option opts cy2 [Integer] (50) the y-coordinate of the second control point. Supports Unit Conversion, see {file:README.md#Units Units}. # @option opts cy2 [Integer] (50) the y-coordinate of the second control point. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts stroke_color [String] (:black) the color with which to stroke the line. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}. # @option opts stroke_color [String] (:black) the color with which to stroke the line. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}.
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}. # @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts fill_color [String] ('#0000') the color with which to fill the triangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
# @return [nil] intended to be void # @return [nil] intended to be void
# @api public # @api public
def curve(opts = {}) def curve(opts = {})
@ -166,5 +167,31 @@ module Squib
end end
end end
# Draw a star at the given x,y
# @example
# star x: 10, y: 10, n: 5, angle: Math::PI / 4, inner_radius: 50, outer_radius: 100,
# fill_color: :green, stroke_color: :burgundy, :stroke_width: 3
#
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
# @option opts x [Fixnum] (0) the x-coordinate of the center. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts y [Fixnum] (0) the y-coordinate of the center. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts n [Integer] (5) the number of points on the star
# @option opts angle [Fixnum] (0) the angle at which to rotate
# @option opts stroke_color [String] (:black) the color with which to stroke the line. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}.
# @option opts stroke_width [Decimal] (2.0) the width of the outside stroke. Supports Unit Conversion, see {file:README.md#Units Units}.
# @option opts fill_color [String] ('#0000') the color with which to fill the triangle. See {file:README.md#Specifying_Colors___Gradients Specifying Colors & Gradients}
# @return [nil] intended to be void
# @api public
def star(opts = {})
opts = needs(opts, [:range, :x, :y, :n, :angle, :inner_radius, :outer_radius,
:layout, :fill_color, :stroke_color, :stroke_width])
opts[:range].each do |i|
@cards[i].star(opts[:x][i], opts[:y][i], opts[:n][i], opts[:angle][i],
opts[:inner_radius][i], opts[:outer_radius][i],
opts[:fill_color][i], opts[:stroke_color][i],
opts[:stroke_width][i])
end
end
end end
end end

3
lib/squib/constants.rb

@ -30,13 +30,16 @@ module Squib
:gap => 0, :gap => 0,
:height => :native, :height => :native,
:hint => :off, :hint => :off,
:inner_radius => 50,
:img_dir => '.', :img_dir => '.',
:justify => false, :justify => false,
:key => '*', :key => '*',
:margin => 75, :margin => 75,
:markup => false, :markup => false,
:mask => nil, :mask => nil,
:n => 5,
:offset => 1.1, :offset => 1.1,
:outer_radius => 100,
:prefix => 'card_', :prefix => 'card_',
:progress_bar => false, :progress_bar => false,
:quotes => :dumb, :quotes => :dumb,

22
lib/squib/graphics/shapes.rb

@ -102,5 +102,27 @@ module Squib
end end
end end
# :nodoc:
# @api private
def star(x, y, n, angle, inner_radius, outer_radius, fill_color, stroke_color, stroke_width)
use_cairo do |cc|
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.set_source_squibcolor(stroke_color)
cc.set_line_width(stroke_width)
cc.stroke_preserve
cc.set_source_squibcolor(fill_color)
cc.fill
end
end
end end
end end

3
samples/draw_shapes.rb

@ -25,5 +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,
fill_color: :burgundy, stroke_color: :cyan, stroke_width: 8
save_png prefix: 'shape_' save_png prefix: 'shape_'
end end

2
squib.sublime-project vendored

@ -20,7 +20,7 @@
// {"name": "rake run[config_text_markup]", "shell_cmd": "rake run[config_text_markup]",}, // {"name": "rake run[config_text_markup]", "shell_cmd": "rake run[config_text_markup]",},
// {"name": "rake run[csv_import]", "shell_cmd": "rake run[csv_import]",}, // {"name": "rake run[csv_import]", "shell_cmd": "rake run[csv_import]",},
// {"name": "rake run[custom_config]", "shell_cmd": "rake run[custom_config]",}, // {"name": "rake run[custom_config]", "shell_cmd": "rake run[custom_config]",},
// {"name": "rake run[draw_shapes]", "shell_cmd": "rake run[draw_shapes]",}, {"name": "rake run[draw_shapes]", "shell_cmd": "rake run[draw_shapes]",},
// {"name": "rake run[embed_text]", "shell_cmd": "rake run[embed_text]",}, // {"name": "rake run[embed_text]", "shell_cmd": "rake run[embed_text]",},
// {"name": "rake run[load_images]", "shell_cmd": "rake run[load_images]",}, // {"name": "rake run[load_images]", "shell_cmd": "rake run[load_images]",},
// {"name": "rake run[text_options]", "shell_cmd": "rake run[text_options]",}, // {"name": "rake run[text_options]", "shell_cmd": "rake run[text_options]",},

Loading…
Cancel
Save