Module: Savage::Transformable

Included in:
Direction, Path, SubPath
Defined in:
lib/savage/transformable.rb

Instance Method Summary collapse

Instance Method Details

#rotate(angle, cx = 0, cy = 0) ⇒ Object

Public: rotate by angle degrees

  • angle : rotation in degrees

  • cx : center x

  • cy : center y

Returns nil

TODO: make cx, cy be origin center



33
34
35
36
37
38
# 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) ⇒ Object



19
20
21
# File 'lib/savage/transformable.rb', line 19

def scale(sx, sy=sx)
  transform( sx, 0, 0, sy, 0, 0 )
end

#skew_x(angle) ⇒ Object



40
41
42
43
# 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) ⇒ Object



45
46
47
48
# 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) ⇒ Object

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



12
13
# File 'lib/savage/transformable.rb', line 12

def transform(a, b, c, d, e, f)
end

#translate(tx, ty = 0) ⇒ Object



15
16
17
# File 'lib/savage/transformable.rb', line 15

def translate(tx, ty=0)
  transform( 1, 0, 0, 1, tx, ty )
end