Sha256: bc8f5b3de791d45a05a7f64a6f9ade56c7ef70dd6958462f03b638e559c98046
Contents?: true
Size: 824 Bytes
Versions: 6
Compression:
Stored size: 824 Bytes
Contents
# # module Turnable extend Trait Left = :turn_left Right = :turn_right def self.included base base.extend ClassMethods end # Defines a turn_speed method on the class. # # Calling it will define a turn_speed method on the instance # that lets the thing rotate with the given frequency. # module ClassMethods def turn_speed amount amount = (amount.to_f*SUBSTEPS) / 10 define_method :turn_speed do amount end end end # # def turn_speed 0.5 # Default turn speed end # Turns the thing left, depending on turn speed. # def turn_left self.rotation -= self.turn_speed / (SUBSTEPS**2) end # Turns the thing right, depending on turn speed. # def turn_right self.rotation += self.turn_speed / (SUBSTEPS**2) end end
Version data entries
6 entries across 6 versions & 1 rubygems