Skip to content

Commit

Permalink
convert rotationDirectionClockwise to Property and instrument, #151
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Oct 6, 2017
1 parent d75ad5b commit 6efc121
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
26 changes: 17 additions & 9 deletions js/photon-absorption/model/Molecule.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,21 @@ define( function( require ) {
this.currentRotationRadians = 0; // @public


// Boolean values that track whether the molecule is vibrating or rotating.
// @public
this.vibratingProperty = new Property( false, { tandem: options.tandem.createTandem( 'vibratingProperty'), phetioValueType: TBoolean});
this.rotatingProperty = new Property( false, { tandem: options.tandem.createTandem( 'rotatingProperty'), phetioValueType: TBoolean});
this.rotationDirectionClockwise = true; // Controls the direction of rotation.
// @public - Boolean values that track whether the molecule is vibrating or rotating.
this.vibratingProperty = new Property( false, {
tandem: options.tandem.createTandem( 'vibratingProperty' ),
phetioValueType: TBoolean
} );
this.rotatingProperty = new Property( false, {
tandem: options.tandem.createTandem( 'rotatingProperty' ),
phetioValueType: TBoolean
} );

// Controls the direction of rotation.
this.rotationDirectionClockwiseProperty = new Property( true, {
tandem: options.tandem.createTandem( 'rotationDirectionClockwiseProperty' ),
phetioValueType: TBoolean
} );

// @public, set by PhotonAbsorptionModel
this.photonGroupTandem = null;
Expand Down Expand Up @@ -154,7 +164,7 @@ define( function( require ) {
/**
* @public
*/
dispose: function(){
dispose: function() {
this.vibratingProperty.dispose();
this.rotatingProperty.dispose();
},
Expand Down Expand Up @@ -237,7 +247,7 @@ define( function( require ) {
}

if ( this.rotatingProperty.get() ) {
var directionMultiplier = this.rotationDirectionClockwise ? -1 : 1;
var directionMultiplier = this.rotationDirectionClockwiseProperty.get() ? -1 : 1;
this.rotate( dt * ROTATION_RATE * 2 * Math.PI * directionMultiplier );
}

Expand Down Expand Up @@ -488,7 +498,6 @@ define( function( require ) {
absorptionHysteresisCountdownTime: this.absorptionHysteresisCountdownTime,
currentVibrationRadians: this.currentVibrationRadians,
currentRotationRadians: this.currentRotationRadians,
rotationDirectionClockwise: this.rotationDirectionClockwise
};
}
}, {
Expand All @@ -506,7 +515,6 @@ define( function( require ) {
molecule.absorptionHysteresisCountdownTime = stateObject.absorptionHysteresisCountdownTime;
molecule.currentVibrationRadians = stateObject.currentVibrationRadians;
molecule.currentRotationRadians = stateObject.currentRotationRadians;
molecule.rotationDirectionClockwise = stateObject.rotationDirectionClockwise;

// add the atoms
molecule.atoms = _.map( stateObject.atoms, function( atom ) { return Atom.fromStateObject( atom ); } );
Expand Down
6 changes: 1 addition & 5 deletions js/photon-absorption/model/RotationStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,16 @@ define( function( require ) {
* and set the direction of rotation to a random direction.
*/
photonAbsorbed: function() {

this.molecule.rotationDirectionClockwise = RAND.nextBoolean();
this.molecule.rotationDirectionClockwiseProperty.value = RAND.nextBoolean();
this.molecule.rotatingProperty.value = true;

},

/**
* Re-emit the absorbed photon. Set the molecule to a non-rotating state.
*/
reemitPhoton: function() {

PhotonHoldStrategy.prototype.reemitPhoton.call( this );
this.molecule.rotatingProperty.value = false;

}

} );
Expand Down

0 comments on commit 6efc121

Please sign in to comment.