Skip to content

Commit

Permalink
did a bunch of cleanup as part of the code review, see #48
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Mar 8, 2016
1 parent ef05483 commit b0e7642
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 42 deletions.
8 changes: 4 additions & 4 deletions js/gravity-force-lab-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ define( function( require ) {
var SimLauncher = require( 'JOIST/SimLauncher' );
var Sim = require( 'JOIST/Sim' );
var GravityForceLabModel = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/model/GravityForceLabModel' );
var GravityForceLabView = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/view/GravityForceLabView' );
var GravityForceLabScreenView = require( 'GRAVITY_FORCE_LAB/gravity-force-lab/view/GravityForceLabScreenView' );

// strings
var gravityForceLabTitleString = require( 'string!GRAVITY_FORCE_LAB/gravity-force-lab.title' );

var simOptions = {
credits: {
softwareDevelopment: 'Sam Reid, John Blanco',
softwareDevelopment: 'Sam Reid, John Blanco, Aadish Gupta',
team: 'Wendy Adams, Trish Loeblein, Noah Podolefsky, Carl Wieman',
qualityAssurance: 'Steele Dalton, Bryce Griebenow, Elise Morgan, Oliver Orejola, Ben Roberts, Bryan Yoelin',
thanks: 'Thanks to Mobile Learner Labs for working with the PhET development team to convert this simulation to HTML5.'
}
};

SimLauncher.launch( function() {
//Create and start the sim
// create and start the sim
new Sim( gravityForceLabTitleString, [
new Screen( gravityForceLabTitleString, null,
function() { return new GravityForceLabModel(); },
function( model ) { return new GravityForceLabView( model ); },
function( model ) { return new GravityForceLabScreenView( model ); },
{ backgroundColor: '#FFFFFF' }
)
], simOptions ).start();
Expand Down
5 changes: 3 additions & 2 deletions js/gravity-force-lab/model/GravityForceLabModel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013-2015, University of Colorado Boulder

/**
* main Model container.
* main model for the Gravity Force Lab simulation
*
* @author Anton Ulyanov (Mlearner)
* @author Aadish Gupta
Expand All @@ -15,7 +15,7 @@ define( function( require ) {
var inherit = require( 'PHET_CORE/inherit' );
var Range = require( 'DOT/Range' );

// Constants
// constants
var G = 6.67384E-11; // gravitational constant
var MIN_SEPARATION_BETWEEN_MASSES = 0.1; // in meters
var LEFT_BOUNDARY = -7.48; // empirically determined for model space in meters
Expand Down Expand Up @@ -57,6 +57,7 @@ define( function( require ) {
}

inherit( PropertySet, GravityForceLabModel, {

step: function() {
// making sure masses doesn't goes out of bounds and don't overlap each other
var minX = LEFT_BOUNDARY + PULL_OBJECT_WIDTH + this.mass1.radius;
Expand Down
23 changes: 11 additions & 12 deletions js/gravity-force-lab/model/Mass.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,27 @@ define( function( require ) {
var inherit = require( 'PHET_CORE/inherit' );
var PropertySet = require( 'AXON/PropertySet' );

//constants
// constants
var DENSITY = 150; // kg/m^3
var CONSTANT_RADIUS = 0.5; // in meters
var CONSTANT_MASS_COLOR = new Color( 'indigo' );
var COLOR_REDUCTION_CONSTANT = 1000; // empirically determined

/**
*
* @param {number} mass
* @param {number} position
* @param {String} color
* @param {number} initialMass
* @param {number} initialPosition
* @param {String} baseColor
* @param {Property.<boolean>} constantRadiusProperty
* @constructor
*/
function Mass( mass, position, color, constantRadiusProperty ) {
function Mass( initialMass, initialPosition, baseColor, constantRadiusProperty ) {
var self = this;
var baseColor = new Color( color );
var radius = this.calculateRadius( mass );
var initialRadius = this.calculateRadius( initialMass );
PropertySet.call( this, {
mass: mass,
position: position,
radius: radius,
baseColor: baseColor
mass: initialMass,
position: initialPosition,
radius: initialRadius,
baseColor: new Color( baseColor )
});

this.massProperty.lazyLink( function( mass ){
Expand All @@ -61,6 +59,7 @@ define( function( require ) {
}

return inherit( PropertySet, Mass, {

// calculates the radius based on mass of object maintaining constant density
// calculations are made using the density formula and volume of a sphere
calculateRadius: function( mass ) {
Expand Down
4 changes: 2 additions & 2 deletions js/gravity-force-lab/view/ControlMass.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013-2015, University of Colorado Boulder

/**
* Slider and button for changing a mass.
* slider and buttons for changing a mass
*
* @author Anton Ulyanov (Mlearner)
* @author Aadish Gupta
Expand Down Expand Up @@ -105,7 +105,7 @@ define( function( require ) {
plusButton.centerY = valueField.centerY;
minusButton.right = valueField.left - 10; // minus button to the left of the value
minusButton.centerY = valueField.centerY;
slider.centerX = slider.centerX + 5; // emperically determined for positioning
slider.centerX = slider.centerX + 5; // empirically determined for positioning

// wrap in a panel
this.addChild( new Panel( content, {
Expand Down
2 changes: 1 addition & 1 deletion js/gravity-force-lab/view/ControlShowValues.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013-2015, University of Colorado Boulder

/**
* Control that allows the user to show or hide the force values.
* control that allows the user to show or hide the force values
*
* @author Anton Ulyanov (Mlearner)
*/
Expand Down
5 changes: 3 additions & 2 deletions js/gravity-force-lab/view/GravityForceLabRuler.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013-2015, University of Colorado Boulder

/**
* Ruler Node.
* ruler node
*
* @author Anton Ulyanov (Mlearner)
*/
Expand All @@ -19,6 +19,7 @@ define( function( require ) {
// constants
var RULER_WIDTH = 500;
var RULER_HEIGHT = 50;

// strings
var unitsMetersString = require( 'string!GRAVITY_FORCE_LAB/units.meters' );

Expand All @@ -43,7 +44,7 @@ define( function( require ) {
} );

this.addInputListener( new MovableDragHandler( model.rulerProperty, {
dragBounds: new Bounds2( -self.width / 2, 0, screenWidth - self.width / 2, screenHeight - self.height)
dragBounds: new Bounds2( -self.width / 2, 0, screenWidth - self.width / 2, screenHeight - self.height )
} ) );
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013-2015, University of Colorado Boulder

/**
* main ScreenView container.
* main ScreenView container
*
* @author Anton Ulyanov (Mlearner)
* @author Aadish Gupta
Expand All @@ -19,19 +19,18 @@ define( function( require ) {
var ScreenView = require( 'JOIST/ScreenView' );
var Vector2 = require( 'DOT/Vector2' );

function GravityForceLabView( model ) {
function GravityForceLabScreenView( model ) {
ScreenView.call( this, { layoutBounds: new Bounds2( 0, 0, 768, 464 ) } );

// Create the model-view transform. The primary units used in the model
// are meters, so significant zoom is used. The multipliers for the 2nd
// parameter can be used to adjust where the point (0, 0) in the model,
// which is between the two masses
// Create the model-view transform. The primary units used in the model are meters, so significant zoom is used.
// The multipliers for the 2nd parameter can be used to adjust where the point (0, 0) in the model, which is
// between the two masses.
var modelViewTransform = ModelViewTransform2.createSinglePointScaleInvertedYMapping(
Vector2.ZERO,
new Vector2( this.layoutBounds.width / 2, this.layoutBounds.height / 2 ),
50 );

this.modelViewTransform = modelViewTransform; // Make mvt available to descendant types.
this.modelViewTransform = modelViewTransform; // Make MVT available to descendant types.

this.addChild( new MassObjects( model, this.layoutBounds.width, this.layoutBounds.height, modelViewTransform ) );

Expand All @@ -44,6 +43,6 @@ define( function( require ) {
controlPanel.top = gravityForceLabRuler.bottom + 15;
}

inherit( ScreenView, GravityForceLabView );
return GravityForceLabView;
inherit( ScreenView, GravityForceLabScreenView );
return GravityForceLabScreenView;
} );
15 changes: 8 additions & 7 deletions js/gravity-force-lab/view/MassObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,22 @@ define( function( require ) {
}, options );

var thisNode = this;
//Conversion functions

// conversion functions
var forceToArrow = new LinearFunction( arrowForceRange.min, arrowForceRange.max, 1, 60, false );
var forceToArrowMin = new LinearFunction( 0, arrowForceRange.min, 0, 1, false );
var forceToImage = new LinearFunction( pullForceRange.min, pullForceRange.max, 0, PULL_IMAGES_COUNT - 1, true );

Node.call( this );
var dragNode = new Node( { cursor: 'pointer' } );
this.pull = new PullObject( { image_count: PULL_IMAGES_COUNT } );
this.pullerNode = new PullObject( { image_count: PULL_IMAGES_COUNT } );
if ( options.direction === 'right' ) {
self.pull.scale( -1, 1 );
self.pullerNode.scale( -1, 1 );
}
var radius = modelViewTransform.modelToViewDeltaX( massModel.radius );
this.massCircle = new Circle( radius );

dragNode.addChild( this.pull );
dragNode.addChild( this.pullerNode );
dragNode.addChild( this.massCircle );
dragNode.addChild( new Circle( 2, { fill: '#000' } ) );
var labelFont = new PhetFont( 12 );
Expand Down Expand Up @@ -163,7 +164,7 @@ define( function( require ) {
stroke: null
} );
thisNode.addChild( arrowNode );
self.pull.setPull( Math.round( forceToImage( model.force ) ), (self.massCircle.width / 2) );
self.pullerNode.setPull( Math.round( forceToImage( model.force ) ), (self.massCircle.width / 2) );
};

massModel.positionProperty.link( function( prop ) {
Expand Down Expand Up @@ -203,8 +204,8 @@ define( function( require ) {
},
drag: function( event ) {
var x = thisNode.globalToParentPoint( event.pointer.point ).x - massClickXOffset;
var xMax = screenWidth - self.massCircle.width / 2 - self.pull.width - OFFSET;
var xMin = OFFSET + self.massCircle.width / 2 + self.pull.width;
var xMax = screenWidth - self.massCircle.width / 2 - self.pullerNode.width - OFFSET;
var xMin = OFFSET + self.massCircle.width / 2 + self.pullerNode.width;
// for mass1 xMax is left boundary of
var sumRadius = modelViewTransform.modelToViewDeltaX( model.mass1.radius ) + modelViewTransform.modelToViewDeltaX( model.mass2.radius );
if ( massModel.position === model.mass1.position ) {
Expand Down
6 changes: 3 additions & 3 deletions js/gravity-force-lab/view/PullObject.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013-2015, University of Colorado Boulder

/**
* pull view for massObject
* puller view for massObject
*
* @author Anton Ulyanov (Mlearner)
*/
Expand Down Expand Up @@ -32,8 +32,8 @@ define( function( require ) {
var pullImage13 = require( 'image!GRAVITY_FORCE_LAB/pull_figure_13.png' );
var pullImage14 = require( 'image!GRAVITY_FORCE_LAB/pull_figure_14.png' );

var pullImages = [ pullImage0, pullImage1, pullImage2, pullImage3, pullImage4, pullImage5, pullImage6, pullImage7, pullImage8, pullImage9, pullImage10,
pullImage11, pullImage12, pullImage13, pullImage14 ];
var pullImages = [ pullImage0, pullImage1, pullImage2, pullImage3, pullImage4, pullImage5, pullImage6, pullImage7,
pullImage8, pullImage9, pullImage10, pullImage11, pullImage12, pullImage13, pullImage14 ];

function PullObject( options ) {
options = _.extend( { ropeLength: 50 }, options );
Expand Down

0 comments on commit b0e7642

Please sign in to comment.