Skip to content

Commit

Permalink
Clear entire wave area when plane wave frequency changes, see #309
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jan 11, 2019
1 parent 1cd86d1 commit 3b4141e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions js/common/model/Lattice.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,9 @@ define( require => {
clearRight( column ) {
for ( let i = column; i < this.width; i++ ) {
for ( let j = 0; j < this.height; j++ ) {
this.setCurrentValue( i, j, 0 );
this.setLastValue( i, j, 0 );
for ( let k = 0; k < this.matrices.length; k++ ) {
this.matrices[ k ].set( i, j, 0 );
}
this.visitedMatrix.set( i, j, 0 );
this.allowedMask.set( i, j, 1 ); // Initialize to 1 to support plane waves, which is never masked.
}
Expand Down
18 changes: 17 additions & 1 deletion js/common/model/Scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ define( require => {
// @private
this.stepIndex = 0;

// @private - when the plane wave frequency is changed, don't update the wave area for a few frames so there is no
// flicker, see https://github.com/phetsims/wave-interference/issues/309
this.stepsToSkipForPlaneWaveSources = 0;

// When the user changes disturbance type, the button pops out and waves stop
this.disturbanceTypeProperty.link( () => {
this.button1PressedProperty.value = false;
Expand Down Expand Up @@ -322,7 +326,11 @@ define( require => {

// When changing the plane wave frequency, clear the wave area to the right of the wave
if ( this.waveSpatialType === Scene.WaveSpatialType.PLANE ) {
this.lattice.clearRight( this.barrierLatticeCoordinateProperty.value );
this.clear();

// when the plane wave frequency is changed, don't update the wave area for a few frames so there is no
// flicker, see https://github.com/phetsims/wave-interference/issues/309
this.stepsToSkipForPlaneWaveSources = 2;
}
else {
this.handlePhaseChanged();
Expand Down Expand Up @@ -460,6 +468,13 @@ define( require => {
* @private
*/
setPlaneSourceValues( amplitude, time ) {

// When the plane wave frequency is changed, don't update the wave area for a few frames so there is no flicker,
// see https://github.com/phetsims/wave-interference/issues/309
if ( this.stepsToSkipForPlaneWaveSources > 0 ) {
this.stepsToSkipForPlaneWaveSources--;
return;
}
const lattice = this.lattice;

const barrierLatticeX = this.barrierTypeProperty.value === Scene.BarrierType.NO_BARRIER ?
Expand Down Expand Up @@ -745,6 +760,7 @@ define( require => {
this.continuousWave2OscillatingProperty.reset();
this.isAboutToFireProperty.reset();
this.barrierTypeProperty && this.barrierTypeProperty.reset();
this.stepsToSkipForPlaneWaveSources = 0;
}

/**
Expand Down

0 comments on commit 3b4141e

Please sign in to comment.