Wrap text
Report abuse
require 'matrix'
#
# Extensions to built-in Ruby classes
#
class Matrix
def self.rotation(angle)
cos_a, sin_a = Math.cos(angle), Math.sin(angle)
Matrix[ [cos_a, -sin_a], [sin_a, cos_a] ]
end
def self.reflection; Matrix[ [1,0], [0, -1] ]; end
end
class Array
def to_s
return self.inspect if not self[0].is_a? Float
inject("[") {|p,q| p += sprintf(" %.1f",q)} + "]"
end
end
class Vector
def rotateBy radians; Matrix.rotation(radians) * self; end
def reflection; Vector[@elements[X], -@elements[Y]]; end
def reflectBy radians; reflection.rotateBy(radians); end
def angle; Math.atan2(@elements[Y], @elements[X]); end
def ratio; @elements[Y] / @elements[X]; end
def area; @elements.inject(4) {|x,y| x*y}; end
def within?(size)
each2(size) { |self_i, size_i| return false if self_i.abs > size_i }
true
end
def to_s; to_a.to_s; end
end
BOUNDS = Vector[1500.0, 1250.0]
SCREEN_SIZE = Vector[700.0, 500.0]
SCREEN_ORIGIN = SCREEN_SIZE * 0.5
SHELL_SIZE = Vector[2.0,2.0]
TANK_SIZE = Vector[10.0,15.0]
MUZZLE_SIZE = Vector[25.0,0.0]
Shoes.app do
b = Vector[-500.0, 250.0]
para b.to_s
end