1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
require "rghost/ps_object"
require "rghost/units"
# Draw a circle to the current path(or current row by default).
#===Options
#
# * <tt>:x and :y</tt> - as center of the circle.
# * <tt>:radius</tt> - as radius(in points).
# * <tt>:ang1</tt> - the angle of a vector from (:x , :y ) of length :radius to the first endpoint of the circle.
# * <tt>:ang2</tt> - the angle of a vector from (:x, :y) of length :radius to the second endpoint of the circle.
# * <tt>:content</tt> - facade to ShapeContent with same parameters.
# * <tt>:border</tt> - facade to Border with same parameters.
# * <tt>:use</tt> - <b>:arc</b> draw counterclockwise and <b>:arcn</b> (arc negative) clockwise direction.
#===Examples using facade circle method inside of Document
# d=Document.new
# d.circle :x => 5, :y => 2.5 , :radius => 40
#
# link:images/circle01.png
# d=Document.new
# d.circle :x => 5, :y => 2.5 , :radius => 40, :content => {:fill => false}
#
# link:images/circle02.png
#
# d=Document.new
# d.circle :x => 5, :y => 2.5 , :radius => 40, :content => {:color => "#FF0000"}
#
# link:images/circle03.png
#
# d=Document.new
# d.circle :x => 5, :y => 2.5 , :radius => 40, :content => {:color => "#FF0000"} ,:border => {:color => "#FFFFFF"}
#
# link:images/circle04.png
#
# d=Document.new
# d.circle :x => 5, :y => 2.5 , :radius => 40, :content => {:color => :yellow} ,:border => {:color => :orange, :dash => [1,2,1,2], :width => 20}
#
# link:images/circle05.png
#
# d=Document.new
# colors=%w[#98AE09 #AFE099 #A971FF #CC1010 #FF7201 #34FEE1]
# 6.downto(1) do |v|
# d.circle :x => 5, :y => 2.5 , :radius => v*10, :content =>{:color => colors[v]}
# end
#
# link:images/circle06.png
# d=Document.new
# d.circle :x => 5, :y => 2.5 , :ang1 => 90, :radius => 50, :content => {:fill => false }
#
# link:images/circle07.png
#
# d=Document.new
# d.circle :x => 5, :y => 2.5 , :ang2 => 90, :radius => 50, :content => {:fill => false }
#
# link:images/circle08.png
#
# d=Document.new
# d.circle :x => 5, :y => 2.5 , :ang2 => 90, :radius => 50, :content =>{:color => :green}
#
# link:images/circle09.png
#
# d=Document.new
# d.circle :x => 5, :y => 2.5 , :ang2 => 90, :use => :arcn, :radius => 50, :content =>{:color => :green}
#
# link:images/circle10.png
#
#===Examples using Circle class
# d=Document.new
# d.scale(3,1)
# d.set Circle.new(:x => 1.5, :y => 1.5 , :ang2 => 180, :radius => 25)
#
# link:images/circle11.png
class RGhost::Circle < RGhost::PsObject
DEFAULT_OPTIONS = {
x: :limit_left,
y: :current_row,
radius: 50,
ang1: 0,
ang2: 360,
use: :arc,
content: RGhost::ShapeContent::DEFAULT_OPTIONS,
border: RGhost::Border::DEFAULT_OPTIONS
}
def initialize(options = {})
super("") {}
@options = DEFAULT_OPTIONS.dup.merge(options)
end
def ps
x, y = RGhost::Units.parse(@options[:x]), RGhost::Units.parse(@options[:y]) # with parse
graph = RGhost::Graphic.new
graph.raw :newpath
graph.set RGhost::Border.new(@options[:border]) if @options[:border]
graph.raw "#{x} #{y} #{@options[:radius]} #{@options[:ang1]} #{@options[:ang2]} #{@options[:use]} "
graph.set RGhost::ShapeContent.new(@options[:content]) if @options[:content]
graph.raw :stroke
graph
end
end
|