Skip to content

Commit

Permalink
added prototype sound generator for wall charges, see #486
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Feb 23, 2021
1 parent 79fbb7c commit 2acccf5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions js/balloons-and-static-electricity/model/WallModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ class WallModel {
for ( let i = 0; i < this.numX; i++ ) {
for ( let k = 0; k < this.numY; k++ ) {

//plus
// plus
const position = this.calculatePosition( i, k );
const plusCharge = new PointChargeModel( x + position[ 0 ], position[ 1 ], Tandem.OPT_OUT, false );
this.plusCharges.push( plusCharge );

//minus
// minus
const minusCharge = new MovablePointChargeModel(
x + position[ 0 ] - PointChargeModel.RADIUS,
position[ 1 ] - PointChargeModel.RADIUS,
Expand Down
38 changes: 37 additions & 1 deletion js/balloons-and-static-electricity/view/WallNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
@author Vasily Shakhov (Mlearner)
*/

import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import Bounds2 from '../../../../dot/js/Bounds2.js';
import Range from '../../../../dot/js/Range.js';
import Image from '../../../../scenery/js/nodes/Image.js';
import Node from '../../../../scenery/js/nodes/Node.js';
import DiscreteSoundGenerator from '../../../../tambo/js/sound-generators/DiscreteSoundGenerator.js';
import soundManager from '../../../../tambo/js/soundManager.js';
import wallImage from '../../../images/wall_png.js';
import balloonsAndStaticElectricity from '../../balloonsAndStaticElectricity.js';
import BASEA11yStrings from '../BASEA11yStrings.js';
import MinusChargesCanvasNode from './MinusChargesCanvasNode.js';
import PlusChargeNode from './PlusChargeNode.js';
import WallDescriber from './describers/WallDescriber.js';
import chargeDeflectionSound from '../../../../tambo/sounds/release_mp3.js';
// import chargeDeflectionSound from '../../../../tambo/sounds/grab_mp3.js';
// import chargeDeflectionSound from '../../../../tambo/sounds/bright-marimba-short_mp3.js';
// import chargeDeflectionSound from '../../../../tambo/sounds/slider-click-01_mp3.js';
// import chargeDeflectionSound from '../../../../tambo/sounds/slider-click-01_mp3.js';

const wallLabelString = BASEA11yStrings.wallLabel.value;

Expand Down Expand Up @@ -69,12 +78,39 @@ class WallNode extends Node {
this.visible = isVisible;
} );

//s how charges based on draw property
// show charges based on draw property
model.showChargesProperty.link( value => {
plusChargesNode.visible = ( value === 'all' );
minusChargesNode.visible = ( value === 'all' );
} );

// TODO: The following is a temporary prototype of sound generation for changes in the wall. It's mostly a proof
// of concept at this point, and will be replaced with something more thought out shortly. See
// https://github.com/phetsims/balloons-and-static-electricity/issues/486.
const nonDeflectedXPosition = model.wall.minusCharges[ 0 ].positionProperty.value.x;
const maxDeflectedXPosition = 739; // empirically determined

_.times( model.wall.numY, index => {
if ( index % 3 === 0 ){
const xPositionProperty = new DerivedProperty(
[ model.wall.minusCharges[ index ].positionProperty ],
positionVector => positionVector.x
);
const deflectionSoundGenerator = new DiscreteSoundGenerator(
xPositionProperty,
new Range( nonDeflectedXPosition, maxDeflectedXPosition ),
{
sound: chargeDeflectionSound,
playbackRateRange: new Range( 1, 2 ),
numBins: 15,
initialOutputLevel: 0.2,
outOfRangeValuesOK: true
}
);
soundManager.addSoundGenerator( deflectionSoundGenerator );
}
} );

// pdom - when the balloons change position, update the description of the induced charge in the wall
const updateWallDescription = () => {
this.setDescriptionContent( this.wallDescriber.getWallDescription( model.yellowBalloon, model.greenBalloon, model.getBalloonsAdjacent() ) );
Expand Down

0 comments on commit 2acccf5

Please sign in to comment.