Skip to content

Commit

Permalink
fixed an issue where the nucleus offset wasn't being set back to zero…
Browse files Browse the repository at this point in the history
… when transitioning from unstable to stable, see phetsims/build-an-atom#146
  • Loading branch information
jbphet committed Mar 10, 2017
1 parent 7b1506f commit 02002fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 7 additions & 0 deletions js/model/Particle.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ define( function( require ) {
} )
} ); // Used in view, integer value, higher means further back.

Property.preventGetSet( this, 'position' );
Property.preventGetSet( this, 'destination' );
Property.preventGetSet( this, 'radius' );
Property.preventGetSet( this, 'animationVelocity' );
Property.preventGetSet( this, 'userControlled' );
Property.preventGetSet( this, 'zLayer' );

options.tandem.addInstance( this, TParticle );
}

Expand Down
12 changes: 7 additions & 5 deletions js/model/ParticleAtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,18 +512,18 @@ define( function( require ) {
nucleons[ 3 ].zLayerProperty.set( 1 );
}
else if ( nucleons.length >= 5 ) {

// This is a generalized algorithm that should work for five or more nucleons.
var placementRadius = 0;
var numAtThisRadius = 1;
var level = 0;
var placementAngle = 0;
var placementAngleDelta = 0;

// Scale correction for the next placement radius, linear map determined empirically.
// As the nucleon size increases, we want the scale factor and change in placement radius
// to decrease since larger nucleons are easier to see with larger area.
// Map values determined in cases which use a wide range in number of nucleons and in
// cases where the nucleon radius scaled from 3 to 10 (in screen coordinates - roughly pixels).
// Scale correction for the next placement radius, linear map determined empirically. As the nucleon size
// increases, we want the scale factor and change in placement radius to decrease since larger nucleons are
// easier to see with larger area. Map values determined in cases which use a wide range in number of nucleons
// and in cases where the nucleon radius scaled from 3 to 10 (in screen coordinates - roughly pixels).
var radiusA = 3;
var radiusB = 10;
var scaleFactorA = 2.4;
Expand All @@ -537,10 +537,12 @@ define( function( require ) {
nucleons[ i ].zLayerProperty.set( level );
numAtThisRadius--;
if ( numAtThisRadius > 0 ) {

// Stay at the same radius and update the placement angle.
placementAngle += placementAngleDelta;
}
else {

// Move out to the next radius.
level++;
placementRadius += nucleonRadius * scaleFactor / level;
Expand Down

0 comments on commit 02002fc

Please sign in to comment.