diff --git a/js/common/model/Lattice.js b/js/common/model/Lattice.js index 88cba163..9ae23f7f 100644 --- a/js/common/model/Lattice.js +++ b/js/common/model/Lattice.js @@ -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. } diff --git a/js/common/model/Scene.js b/js/common/model/Scene.js index b9e59833..851d4a64 100644 --- a/js/common/model/Scene.js +++ b/js/common/model/Scene.js @@ -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; @@ -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(); @@ -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 ? @@ -745,6 +760,7 @@ define( require => { this.continuousWave2OscillatingProperty.reset(); this.isAboutToFireProperty.reset(); this.barrierTypeProperty && this.barrierTypeProperty.reset(); + this.stepsToSkipForPlaneWaveSources = 0; } /**