Skip to content

Commit

Permalink
GFLB constant radius should be the same as min radius, convert Mass a…
Browse files Browse the repository at this point in the history
…nd Charge to es6, removing ISLCObject.calculateRadius abstract method. phetsims/gravity-force-lab-basics#183
  • Loading branch information
zepumph committed Oct 8, 2019
1 parent 8bff6a0 commit 63ad3da
Showing 1 changed file with 33 additions and 44 deletions.
77 changes: 33 additions & 44 deletions js/common/model/Charge.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,43 @@ define( require => {
const coulombsLaw = require( 'COULOMBS_LAW/coulombsLaw' );
const DerivedProperty = require( 'AXON/DerivedProperty' );
const DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' );
const inherit = require( 'PHET_CORE/inherit' );
const ISLCObject = require( 'INVERSE_SQUARE_LAW_COMMON/model/ISLCObject' );

/**
* @param {number} initialCharge
* @param {number} initialPosition - only for the x coordinate
* @param {Range} valueRange - only for the x coordinate
* @param {Tandem} tandem
* @param {Object} options
* @constructor
*/
function Charge( initialCharge, initialPosition, valueRange, tandem, options ) {

options = _.extend( {
constantRadius: 6.75E-3, // ensure this is in meters (0.675cm)
valueUnits: 'coulombs'
}, options );

const constantRadiusProperty = new BooleanProperty( true, {
tandem: tandem.createTandem( 'constantRadiusProperty' )
} );

const negativeColor = new Color( '#00f' );
const positiveColor = new Color( '#f00' );

ISLCObject.call( this, initialCharge, initialPosition, valueRange, constantRadiusProperty, tandem, options );

// see ISLCObject
this.baseColorProperty = new DerivedProperty( [this.valueProperty], function( value ) {
const newBaseColor = value < 0 ? negativeColor : positiveColor;
return newBaseColor.colorUtilsBrighter( 1 - Math.abs( value ) / valueRange.max );
},
{ tandem: tandem.createTandem( 'baseColorProperty' ), phetioType: DerivedPropertyIO( ColorIO ) }
);
}

coulombsLaw.register( 'Charge', Charge );

return inherit( ISLCObject, Charge, {
class Charge extends ISLCObject {

/**
* Returns the radius of the charge object.
*
* @override
* @returns {number}
* @param {number} initialCharge
* @param {number} initialPosition - only for the x coordinate
* @param {Range} valueRange - only for the x coordinate
* @param {Tandem} tandem
* @param {Object} options
*/
calculateRadius: function() {
return this.radiusProperty.get();
constructor( initialCharge, initialPosition, valueRange, tandem, options ) {

options = _.extend( {
constantRadius: 6.75E-3, // ensure this is in meters (0.675cm)
valueUnits: 'coulombs'
}, options );

const constantRadiusProperty = new BooleanProperty( true, {
tandem: tandem.createTandem( 'constantRadiusProperty' )
} );

const negativeColor = new Color( '#00f' );
const positiveColor = new Color( '#f00' );

super( initialCharge, initialPosition, valueRange, constantRadiusProperty,
() => this.radiusProperty.get(), tandem, options );

// see ISLCObject
this.baseColorProperty = new DerivedProperty( [ this.valueProperty ], value => {
const newBaseColor = value < 0 ? negativeColor : positiveColor;
return newBaseColor.colorUtilsBrighter( 1 - Math.abs( value ) / valueRange.max );
},
{ tandem: tandem.createTandem( 'baseColorProperty' ), phetioType: DerivedPropertyIO( ColorIO ) }
);
}
} );
}

return coulombsLaw.register( 'Charge', Charge );
} );

0 comments on commit 63ad3da

Please sign in to comment.