Module | Magick::RVG::Transformable |
In: |
lib/rvg/transformable.rb
|
Transformations are operations on the coordinate system. All the transformations defined within a container (an RVG object or a group) are applied before drawing any shapes or text. All transformations are applied in the order they were defined. Note: This means that
g.translate(10,20).scale(2)
is not the same as
g.scale(2).translate(10,20)
# File lib/rvg/transformable.rb, line 37 37: def initialize(*args, &block) 38: super() 39: @transforms = Transforms.new 40: end
Applies the transformation matrix [sx, rx, ry, sy, tx, ty]
# File lib/rvg/transformable.rb, line 45 45: def matrix(sx, rx, ry, sy, tx, ty) 46: begin 47: @transforms << [:affine, [Float(sx), Float(rx), Float(ry), Float(sy), Float(tx), Float(ty)]] 48: rescue ArgumentError 49: raise ArgumentError, "arguments must be convertable to float (got #{sx.class}, #{rx.class}, #{ry.class}, #{sy.class}, #{sx.class}, #{sx.class}, #{tx.class}, #{ty.class})" 50: end 51: yield(self) if block_given? 52: self 53: end
This method can take either of two argument lists:
# File lib/rvg/transformable.rb, line 86 86: def rotate(angle, *args) 87: begin 88: case args.length 89: when 0 90: @transforms << [:rotate, [Float(angle)]] 91: when 2 92: cx, cy = Float(args[0]), Float(args[1]) 93: @transforms << [:translate, [cx, cy]] 94: @transforms << [:rotate, [angle]] 95: @transforms << [:translate, [-cx, -cy]] 96: else 97: raise ArgumentError, "wrong number of arguments (#{args.length} for 1 or 3)" 98: end 99: rescue ArgumentError 100: raise ArgumentError, "arguments must be convertable to float (got #{[angle, *args].collect {|a| a.class}.join(', ')})" 101: end 102: yield(self) if block_given? 103: self 104: end
Multiply the x-coordinates by sx and the y-coordinates by sy. If sy is omitted it defaults to sx.
# File lib/rvg/transformable.rb, line 71 71: def scale(sx, sy=nil) 72: sy ||= sx 73: begin 74: @transforms << [:scale, [Float(sx), Float(sy)]] 75: rescue ArgumentError 76: raise ArgumentError, "arguments must be convertable to float (got #{sx.class}, #{sy.class})" 77: end 78: yield(self) if block_given? 79: self 80: end
Skew the X-axis by angle degrees.
# File lib/rvg/transformable.rb, line 107 107: def skewX(angle) 108: begin 109: @transforms << [:skewx, [Float(angle)]] 110: rescue ArgumentError 111: raise ArgumentError, "argument must be convertable to float (got #{angle.class})" 112: end 113: yield(self) if block_given? 114: self 115: end
Skew the Y-axis by angle degrees.
# File lib/rvg/transformable.rb, line 118 118: def skewY(angle) 119: begin 120: @transforms << [:skewy, [Float(angle)]] 121: rescue ArgumentError 122: raise ArgumentError, "argument must be convertable to float (got #{angle.class})" 123: end 124: yield(self) if block_given? 125: self 126: end
Add tx to all x-coordinates and ty to all y-coordinates. If ty is omitted it defaults to tx.
# File lib/rvg/transformable.rb, line 58 58: def translate(tx, ty=nil) 59: ty ||= tx 60: begin 61: @transforms << [:translate, [Float(tx), Float(ty)]] 62: rescue ArgumentError 63: raise ArgumentError, "arguments must be convertable to float (got #{tx.class}, #{ty.class})" 64: end 65: yield(self) if block_given? 66: self 67: end