Class: RubySketch::SnapConstraint

Inherits:
Constraint show all
Defined in:
lib/rubysketch/constraint.rb

Overview

Snaps two points together like a hinge.

Instance Method Summary collapse

Methods inherited from Constraint

#active?, #collide=, #collide?, #damping, #damping=, #force, #force=, #remove, #removed?, #spring, #spring=, #sprites

Instance Method Details

#angleRange?

Returns the range of the relative rotation angle.

Returns:

  • (Range, nil)

    radians or degrees depending on angleMode()



198
199
200
201
# File 'lib/rubysketch/constraint.rb', line 198

def angle()
  angle = @constraint__.angle
  angle ? Range.new(fromDegrees__(angle.begin), fromDegrees__(angle.end)) : nil
end

#angle=(angle) ⇒ Range, ...

Sets the range of the relative rotation angle.

Parameters:

  • angle (Range, Numeric, nil)

    radians or degrees depending on angleMode(). nil rotates freely, 0 fixes the rotation

Returns:

  • (Range, Numeric, nil)

    angle



185
186
187
188
189
190
191
192
# File 'lib/rubysketch/constraint.rb', line 185

def angle=(angle)
  @constraint__.angle =
    case angle
    when Range   then Range.new toDegrees__(angle.begin), toDegrees__(angle.end)
    when Numeric then toDegrees__ angle
    else              angle
    end
end

#motorNumeric?

Returns the motor speed.

Returns:

  • (Numeric, nil)

    angular velocity per second



219
220
221
222
# File 'lib/rubysketch/constraint.rb', line 219

def motor()
  speed = @constraint__.motor
  speed && fromDegrees__(speed)
end

#motor=(speed) ⇒ Numeric?

Sets the motor speed that drives the relative rotation.

Parameters:

  • speed (Numeric, nil)

    angular velocity per second, radians or degrees depending on angleMode(). nil stops the motor

Returns:

  • (Numeric, nil)

    speed



211
212
213
# File 'lib/rubysketch/constraint.rb', line 211

def motor=(speed)
  @constraint__.motor = speed && toDegrees__(speed)
end