module Savage::Transformable

Public Instance Methods

rotate( angle, cx=0, cy=0 ) click to toggle source

Public: rotate by angle degrees

  • angle : rotation in degrees

  • cx : center x

  • cy : center y

Returns nil

TODO: make cx, cy be origin center

# File lib/savage/transformable.rb, line 33
def rotate( angle, cx=0, cy=0 )
  a = (angle.to_f/180).to_d * Math::PI
  translate( cx, cy )
  transform( Math.cos(a),  Math.sin(a), -Math.sin(a), Math.cos(a), 0, 0)
  translate( -cx, -cy )
end
scale(sx, sy=sx) click to toggle source
# File lib/savage/transformable.rb, line 19
def scale(sx, sy=sx)
  transform( sx, 0, 0, sy, 0, 0 )
end
skew_x( angle ) click to toggle source
# File lib/savage/transformable.rb, line 40
def skew_x( angle )
  a = angle.to_f/180 * Math::PI
  transform( 1, 0, Math.tan(a), 1, 0, 0 )
end
skew_y( angle ) click to toggle source
# File lib/savage/transformable.rb, line 45
def skew_y( angle )
  a = angle.to_f/180 * Math::PI
  transform( 1, Math.tan(a), 0, 1, 0, 0 )
end
transform(a, b, c, d, e, f) click to toggle source

Matrix 2D: | a, c, e | | b, d, f | | 0, 0, 1 |

# File lib/savage/transformable.rb, line 12
def transform(a, b, c, d, e, f)
end
translate(tx, ty=0) click to toggle source
# File lib/savage/transformable.rb, line 15
def translate(tx, ty=0)
  transform( 1, 0, 0, 1, tx, ty )
end

Protected Instance Methods

transform_dot( dot, a, b, c, d, e, f ) click to toggle source
# File lib/savage/transformable.rb, line 52
def transform_dot( dot, a, b, c, d, e, f )
  x, y  = dot.x, dot.y
  dot.x = x*a + y*c + e
  dot.y = x*b + y*d + f
end