From 4783c00e204c5788797a07659258131dc4873295 Mon Sep 17 00:00:00 2001 From: zepumph Date: Thu, 19 Sep 2019 14:25:01 -0800 Subject: [PATCH] var -> const using eslint auto fix, https://github.com/phetsims/tasks/issues/1012 --- js/common/RSA11yStrings.js | 4 +- js/common/RSColorProfile.js | 2 +- js/common/RSConstants.js | 2 +- js/common/RSQueryParameters.js | 2 +- js/common/model/AlphaParticle.js | 20 ++--- js/common/model/Atom.js | 10 +-- js/common/model/AtomSpace.js | 48 +++++------ js/common/model/Gun.js | 34 ++++---- js/common/model/RSBaseModel.js | 12 +-- .../view/AlphaParticlePropertiesPanel.js | 46 +++++------ js/common/view/MenuOptionsNode.js | 2 +- js/common/view/NuclearParticleLegendPanel.js | 2 +- js/common/view/ParticleLegendPanel.js | 16 ++-- js/common/view/ParticleNodeFactory.js | 28 +++---- js/common/view/ParticleSpaceNode.js | 34 ++++---- js/common/view/RSBaseScreenView.js | 34 ++++---- js/common/view/RSControlPanel.js | 4 +- js/common/view/RSScreenSummaryNode.js | 2 +- js/common/view/ScaleInfoNode.js | 22 ++--- js/common/view/TargetMaterialNode.js | 12 +-- js/common/view/TinyBox.js | 8 +- js/plumpuddingatom/PlumPuddingAtomScreen.js | 2 +- .../view/PlumPuddingAtomScreenView.js | 20 ++--- .../view/PlumPuddingSpaceNode.js | 10 +-- js/rutherford-scattering-main.js | 6 +- js/rutherfordatom/RutherfordAtomScreen.js | 4 +- js/rutherfordatom/model/RutherfordAtom.js | 80 +++++++++---------- .../model/RutherfordAtomSpace.js | 16 ++-- js/rutherfordatom/model/RutherfordNucleus.js | 14 ++-- .../model/RutherfordNucleusSpace.js | 2 +- js/rutherfordatom/view/AtomCollectionNode.js | 30 +++---- .../view/AtomParticleLegendPanel.js | 2 +- js/rutherfordatom/view/AtomPropertiesPanel.js | 72 ++++++++--------- js/rutherfordatom/view/AtomSpaceNode.js | 10 +-- js/rutherfordatom/view/NucleusSpaceNode.js | 10 +-- .../view/RutherfordAtomScreenView.js | 76 +++++++++--------- .../view/RutherfordNucleusNode.js | 60 +++++++------- 37 files changed, 379 insertions(+), 379 deletions(-) diff --git a/js/common/RSA11yStrings.js b/js/common/RSA11yStrings.js index d263d06..2f8c2ad 100644 --- a/js/common/RSA11yStrings.js +++ b/js/common/RSA11yStrings.js @@ -13,7 +13,7 @@ define( require => { // modules const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' ); - var RSA11yStrings = { + const RSA11yStrings = { screenSummary: { value: 'On this screen, the Play Area has a source that can stream Alpha particles onto a thin foil. A highly ' + @@ -103,7 +103,7 @@ define( require => { }; if ( phet.chipper.queryParameters.stringTest === 'xss' ) { - for ( var key in RSA11yStrings ) { + for ( const key in RSA11yStrings ) { RSA11yStrings[ key ].value += ''; } } diff --git a/js/common/RSColorProfile.js b/js/common/RSColorProfile.js index 04b9b53..a1a1a42 100644 --- a/js/common/RSColorProfile.js +++ b/js/common/RSColorProfile.js @@ -20,7 +20,7 @@ define( require => { // the 'default' value provided. // NOTE: This is NOT provided to clients directly, but each of these are passed to the Property constructor, // see ColorProfile.js - var RSColorProfile = new ColorProfile( [ 'default', 'projector' ], { + const RSColorProfile = new ColorProfile( [ 'default', 'projector' ], { backgroundColor: { default: new Color( 0, 0, 0 ), projector: new Color( 255, 255, 255 ) diff --git a/js/common/RSConstants.js b/js/common/RSConstants.js index 87f19f2..45babb6 100644 --- a/js/common/RSConstants.js +++ b/js/common/RSConstants.js @@ -15,7 +15,7 @@ define( require => { const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' ); // constants - var RSConstants = { + const RSConstants = { //---------------------------------------------------------------------------- // Model diff --git a/js/common/RSQueryParameters.js b/js/common/RSQueryParameters.js index bf17662..8cabf1c 100644 --- a/js/common/RSQueryParameters.js +++ b/js/common/RSQueryParameters.js @@ -11,7 +11,7 @@ define( require => { // modules const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' ); - var RSQueryParameters = QueryStringMachine.getAll( { + const RSQueryParameters = QueryStringMachine.getAll( { // show shapes around each atom to show the transform of the atomic bounds as a particle enters the bounding box showDebugShapes: { type: 'flag' }, diff --git a/js/common/model/AlphaParticle.js b/js/common/model/AlphaParticle.js index 7c09730..e70ce1d 100644 --- a/js/common/model/AlphaParticle.js +++ b/js/common/model/AlphaParticle.js @@ -70,8 +70,8 @@ define( require => { this.preparedBoundingBox = null; // @private - save new particle location - var self = this; - var positionListener = function( position ) { + const self = this; + const positionListener = function( position ) { self.positions.push( new Vector2( position.x, position.y ) ); }; this.positionProperty.link( positionListener ); @@ -103,13 +103,13 @@ define( require => { // if there are less than two positions, return a vector pointing in the initial orientation if ( this.positions.length < 2 ) { - var orientation = this.orientationProperty.get(); + const orientation = this.orientationProperty.get(); return new Vector2( Math.cos( orientation ), Math.sin( orientation ) ).normalized(); } - var position1 = this.positions[ this.positions.length - 2 ]; - var position2 = this.positions[ this.positions.length - 1 ]; - var direction = new Vector2( position2.x - position1.x, position2.y - position1.y ); + const position1 = this.positions[ this.positions.length - 2 ]; + const position2 = this.positions[ this.positions.length - 1 ]; + const direction = new Vector2( position2.x - position1.x, position2.y - position1.y ); return direction.normalized(); }, @@ -125,13 +125,13 @@ define( require => { prepareBoundingBox: function( atom ) { // get the angle of the vector orthogonal to the direction of movement - var direction = this.getDirection(); - var perpendicular = direction.perpendicular; + const direction = this.getDirection(); + const perpendicular = direction.perpendicular; - var rotationAngle = perpendicular.angle; + const rotationAngle = perpendicular.angle; this.preparedRotationAngle = rotationAngle; - var transformedShape = atom.boundingRect.transformed( Matrix3.rotationAroundPoint( rotationAngle, atom.position ) ); + const transformedShape = atom.boundingRect.transformed( Matrix3.rotationAroundPoint( rotationAngle, atom.position ) ); this.preparedBoundingBox = transformedShape; } diff --git a/js/common/model/Atom.js b/js/common/model/Atom.js index d4b507d..58a09cf 100644 --- a/js/common/model/Atom.js +++ b/js/common/model/Atom.js @@ -24,13 +24,13 @@ define( require => { // @public (read-only) this.position = position; - var halfWidth = boundingWidth / 2; + const halfWidth = boundingWidth / 2; // @public (read-only) - bounding rect is always square this.boundingRect = Shape.rectangle( position.x - halfWidth, position.y - halfWidth, boundingWidth, boundingWidth ); // @public (read-only) circle which contains the entire bounding box for the atom - var radius = Math.sqrt( halfWidth * halfWidth + halfWidth * halfWidth ); + const radius = Math.sqrt( halfWidth * halfWidth + halfWidth * halfWidth ); this.boundingCircle = Shape.circle( position.x, position.y, radius ); // @private - array of particles that are currently in the bounding box of this atom @@ -59,7 +59,7 @@ define( require => { * @public */ removeParticle: function( alphaParticle ) { - var index = this.particles.indexOf( alphaParticle ); + const index = this.particles.indexOf( alphaParticle ); if ( index > -1 ) { this.particles.splice( index, 1 ); } @@ -88,7 +88,7 @@ define( require => { * @private */ moveParticles: function( dt ) { - var self = this; + const self = this; this.particles.forEach( function( particle ) { self.moveParticle( particle, dt ); } ); @@ -99,7 +99,7 @@ define( require => { * @protected */ cullParticles: function() { - var self = this; + const self = this; this.particles.forEach( function( particle ) { if ( !self.bounds.containsPoint( particle.positionProperty.get() ) ) { self.removeParticle( particle ); diff --git a/js/common/model/AtomSpace.js b/js/common/model/AtomSpace.js index 7569c80..a535697 100644 --- a/js/common/model/AtomSpace.js +++ b/js/common/model/AtomSpace.js @@ -42,7 +42,7 @@ define( require => { // when a particle has been removed from an atom, remove it from the space as well // no need to remove listener, exists for life of sim - var self = this; + const self = this; this.particleRemovedFromAtomEmitter.addListener( function( particle ) { self.removeParticle( particle ); } ); @@ -84,7 +84,7 @@ define( require => { * @public */ removeParticle: function( alphaParticle ) { - var index = this.particles.indexOf( alphaParticle ); + const index = this.particles.indexOf( alphaParticle ); if ( index > -1 ) { this.particles.splice( index, 1 ); this.removeParticleFromEmptySpace( alphaParticle ); @@ -98,7 +98,7 @@ define( require => { * @private */ removeParticleFromEmptySpace: function( alphaParticle ) { - var index = this.particlesInEmptySpace.indexOf( alphaParticle ); + const index = this.particlesInEmptySpace.indexOf( alphaParticle ); if ( index > -1 ) { alphaParticle.isInSpace = false; this.particlesInEmptySpace.splice( index, 1 ); @@ -121,11 +121,11 @@ define( require => { * @private */ transitionParticlesToAtoms: function() { - for ( var i = 0; i < this.particlesInEmptySpace.length; i++ ) { - var particle = this.particlesInEmptySpace[ i ]; + for ( let i = 0; i < this.particlesInEmptySpace.length; i++ ) { + const particle = this.particlesInEmptySpace[ i ]; - for ( var j = 0; j < this.atoms.length; j++ ) { - var atom = this.atoms[ j ]; + for ( let j = 0; j < this.atoms.length; j++ ) { + const atom = this.atoms[ j ]; if ( particle.preparedAtom !== atom && atom.boundingCircle.containsPoint( particle.positionProperty.get() ) ) { particle.prepareBoundingBox( atom ); @@ -163,8 +163,8 @@ define( require => { * @public */ transitionParticlesToSpace: function() { - for ( var i = 0; i < this.particles.length; i++ ) { - var particle = this.particles[ i ]; + for ( let i = 0; i < this.particles.length; i++ ) { + const particle = this.particles[ i ]; if ( !particle.isInSpace ) { // if the particle leaves the bounding circle of its atom, add it back into empty space @@ -191,18 +191,18 @@ define( require => { this.transitionParticlesToSpace(); // move particles in empty space straight through - for ( var i = 0 ; i < this.particles.length; i++ ) { - var alphaParticle = this.particles[ i ]; + for ( let i = 0 ; i < this.particles.length; i++ ) { + const alphaParticle = this.particles[ i ]; if ( !alphaParticle.atom ) { - var speed = alphaParticle.speedProperty.get(); - var distance = speed * dt; - var direction = alphaParticle.orientationProperty.get(); - var dx = Math.cos( direction ) * distance; - var dy = Math.sin( direction ) * distance; - var position = alphaParticle.positionProperty.get(); - var x = position.x + dx; - var y = position.y + dy; + const speed = alphaParticle.speedProperty.get(); + const distance = speed * dt; + const direction = alphaParticle.orientationProperty.get(); + const dx = Math.cos( direction ) * distance; + const dy = Math.sin( direction ) * distance; + const position = alphaParticle.positionProperty.get(); + const x = position.x + dx; + const y = position.y + dy; alphaParticle.positionProperty.set( new Vector2( x, y ) ); } } @@ -221,12 +221,12 @@ define( require => { */ checkAtomBounds: function() { // make sure that none of the atoms overlap each other - for ( var i = 0; i < this.atoms.length - 1; i++ ) { - for ( var j = i + 1; j < this.atoms.length; j++ ) { + for ( let i = 0; i < this.atoms.length - 1; i++ ) { + for ( let j = i + 1; j < this.atoms.length; j++ ) { // get the atom bounds and erode slightly because bounds should perfectly overlap at edges - var atom1Bounds = this.atoms[ i ].boundingRect.bounds; - var atom2Bounds = this.atoms[ j ].boundingRect.bounds; - var boundsIntersect = atom1Bounds.intersectsBounds( atom2Bounds ); + const atom1Bounds = this.atoms[ i ].boundingRect.bounds; + const atom2Bounds = this.atoms[ j ].boundingRect.bounds; + const boundsIntersect = atom1Bounds.intersectsBounds( atom2Bounds ); assert && assert( !boundsIntersect, 'Atom bounds intersect' ); } } diff --git a/js/common/model/Gun.js b/js/common/model/Gun.js index 4143163..73c5f16 100644 --- a/js/common/model/Gun.js +++ b/js/common/model/Gun.js @@ -18,9 +18,9 @@ define( require => { const Vector2 = require( 'DOT/Vector2' ); // constants - var MAX_PARTICLES = 20; - var GUN_INTENSITY = 1; - var X0_MIN_FRACTION = 0.04; // closest particle can get horizontally to atom as a fraction of atomic bounds + const MAX_PARTICLES = 20; + const GUN_INTENSITY = 1; + const X0_MIN_FRACTION = 0.04; // closest particle can get horizontally to atom as a fraction of atomic bounds /** * {RSBaseModel} model @@ -39,10 +39,10 @@ define( require => { // so this correction ensure that this does not happen // map values determined empirically // @private - to prevent function instantiation every animation frame - var width1 = 20; - var width2 = this.model.bounds.width; - var correction1 = 2; - var correction2 = 10; + const width1 = 20; + const width2 = this.model.bounds.width; + const correction1 = 2; + const correction2 = 10; this.correctionFunction = new LinearFunction( width1, width2, correction1, correction2 ); // @public {boolean} is the gun on? @@ -59,25 +59,25 @@ define( require => { */ step: function( dt ) { - var initialSpeed = this.model.alphaParticleEnergyProperty.get(); + const initialSpeed = this.model.alphaParticleEnergyProperty.get(); this.dtSinceGunFired += ( GUN_INTENSITY * dt ); this.dtPerGunFired = ( this.model.bounds.width / initialSpeed ) / MAX_PARTICLES; if ( this.onProperty.get() && this.dtSinceGunFired >= this.dtPerGunFired ) { - var ySign = ( phet.joist.random.nextDouble() < 0.5 ? 1 : -1 ); + const ySign = ( phet.joist.random.nextDouble() < 0.5 ? 1 : -1 ); // random position withing model bounds - var rand = phet.joist.random.nextDouble(); - var particleX = ySign * rand * this.model.bounds.width / 2; + const rand = phet.joist.random.nextDouble(); + let particleX = ySign * rand * this.model.bounds.width / 2; // make sure that the particle was not directly fired at an atom to prevent trajectory failure - var self = this; - var xMin = X0_MIN_FRACTION * this.model.bounds.width; + const self = this; + const xMin = X0_MIN_FRACTION * this.model.bounds.width; this.model.getVisibleSpace().atoms.forEach( function ( atom ) { if ( Math.abs( particleX - atom.position.x ) < xMin ) { - var correction = self.correctionFunction( atom.boundingRect.bounds.width ); + const correction = self.correctionFunction( atom.boundingRect.bounds.width ); if ( particleX > atom.position.x ) { // particle is to the right of nucleus, push it farther away particleX += correction; @@ -87,10 +87,10 @@ define( require => { } } } ); - var particleY = this.model.bounds.minY; + const particleY = this.model.bounds.minY; - var initialPosition = new Vector2( particleX, particleY ); - var alphaParticle = new AlphaParticle( { + const initialPosition = new Vector2( particleX, particleY ); + const alphaParticle = new AlphaParticle( { speed: initialSpeed, defaultSpeed: initialSpeed, position: initialPosition diff --git a/js/common/model/RSBaseModel.js b/js/common/model/RSBaseModel.js index 9ba022c..cf46b13 100644 --- a/js/common/model/RSBaseModel.js +++ b/js/common/model/RSBaseModel.js @@ -58,7 +58,7 @@ define( require => { this.stepEmitter = new Emitter( { parameters: [ { valueType: 'number' } ] } ); // no need to unlink this property as base model will exist for life of sim - var userInteractionListener = userInteraction => { + const userInteractionListener = userInteraction => { if ( userInteraction ) { this.removeAllParticles(); } @@ -85,7 +85,7 @@ define( require => { * @public */ getVisibleSpace: function() { - var visibleSpace; + let visibleSpace; this.atomSpaces.forEach( function( space ) { if ( space.isVisible ) { visibleSpace = space; @@ -116,7 +116,7 @@ define( require => { */ removeParticle: function( alphaParticle ) { // remove the particle from the visible space - var visibleSpace = this.getVisibleSpace(); + const visibleSpace = this.getVisibleSpace(); visibleSpace.removeParticle( alphaParticle ); // remove the particle from its atom if scattered @@ -125,7 +125,7 @@ define( require => { } ); // remove the particle from the base model - var index = this.particles.indexOf( alphaParticle ); + const index = this.particles.indexOf( alphaParticle ); if ( index > -1 ) { this.particles.splice( index, 1 ); } @@ -137,7 +137,7 @@ define( require => { */ removeAllParticles: function() { // remove the particles from the visible space - var visibleSpace = this.getVisibleSpace(); + const visibleSpace = this.getVisibleSpace(); visibleSpace.removeAllParticles(); // remove all particles from the atoms @@ -179,7 +179,7 @@ define( require => { * @protected */ cullParticles: function() { - var self = this; + const self = this; this.particles.forEach( function( particle ) { if ( !self.bounds.containsPoint( particle.positionProperty.get() ) ) { self.removeParticle( particle ); diff --git a/js/common/view/AlphaParticlePropertiesPanel.js b/js/common/view/AlphaParticlePropertiesPanel.js index 8aa0522..9dafed5 100644 --- a/js/common/view/AlphaParticlePropertiesPanel.js +++ b/js/common/view/AlphaParticlePropertiesPanel.js @@ -36,16 +36,16 @@ define( require => { const showTracesString = require( 'string!RUTHERFORD_SCATTERING/showTraces' ); // a11y strings - var alphaParticleSettingsString = RSA11yStrings.alphaParticleSettings.value; - var energySliderDescriptionString = RSA11yStrings.energySliderDescription.value; - var tracesString = RSA11yStrings.traces.value; - var traceCheckboxDescriptionString = RSA11yStrings.traceCheckboxDescription.value; + const alphaParticleSettingsString = RSA11yStrings.alphaParticleSettings.value; + const energySliderDescriptionString = RSA11yStrings.energySliderDescription.value; + const tracesString = RSA11yStrings.traces.value; + const traceCheckboxDescriptionString = RSA11yStrings.traceCheckboxDescription.value; // constants // global, tracks fingers on the slider for multitouch support // must persist beyond individual panel instances so multitouch is supported // when a panel is created or destroyed - var FINGER_TRACKER = {}; + const FINGER_TRACKER = {}; /** * Constructor for a Alpha Particle Properties control panel. @@ -57,14 +57,14 @@ define( require => { function AlphaParticlePropertiesPanel( content, options ) { // the title for the panel - var alphaParticlePropertiesText = new Text( alphaParticlePropertiesString, { + const alphaParticlePropertiesText = new Text( alphaParticlePropertiesString, { font: RSConstants.PANEL_TITLE_FONT, fontWeight: 'bold', fill: RSColorProfile.panelTitleColorProperty, maxWidth: 215 } ); - var contentVBox = new VBox( { + const contentVBox = new VBox( { children: [ alphaParticlePropertiesText, content ], align: 'left', spacing: RSConstants.PANEL_CHILD_SPACING @@ -147,19 +147,19 @@ define( require => { // @private this.energyInteractionProperty = energyInteractionProperty; - var energyText = new Text( energyString, { + const energyText = new Text( energyString, { font: RSConstants.PANEL_PROPERTY_FONT, fontWeight: 'bold', fill: RSColorProfile.panelLabelColorProperty, maxWidth: 210 } ); - var minEnergyText = new Text( minEnergyString, { + const minEnergyText = new Text( minEnergyString, { font: RSConstants.PANEL_TICK_FONT, fill: RSColorProfile.panelSliderLabelColorProperty, maxWidth: options.maxWidth / 5, pickable: false } ); - var maxEnergyText = new Text( maxEnergyString, { + const maxEnergyText = new Text( maxEnergyString, { font: RSConstants.PANEL_TICK_FONT, fill: RSColorProfile.panelSliderLabelColorProperty, maxWidth: options.maxWidth / 5, @@ -167,14 +167,14 @@ define( require => { } ); // slider title - var energyTextStrut = new HStrut( options.minWidth * 0.05 ); - var energyTitleBox = new HBox( { children: [ energyTextStrut, energyText ] } ); + const energyTextStrut = new HStrut( options.minWidth * 0.05 ); + const energyTitleBox = new HBox( { children: [ energyTextStrut, energyText ] } ); /** * Track fingers for multitouch, adding a finger count to the slider and setting the proper * interaction properties. */ - var addFinger = function( elementID ) { + const addFinger = function( elementID ) { energyInteractionProperty.set( true ); if ( !FINGER_TRACKER[ elementID ] && FINGER_TRACKER[ elementID ] !== 0 ) { FINGER_TRACKER[ elementID ] = 1; // first time finger is down on this thumb @@ -188,7 +188,7 @@ define( require => { * Remove a finger from an element for multitouch support, removing a finger count from a particular element * and setting the interaction properties appropriately. */ - var removeFinger = function( elementID ) { + const removeFinger = function( elementID ) { FINGER_TRACKER[ elementID ]--; assert && assert( FINGER_TRACKER[ elementID ] >= 0, 'at least 0 fingers must be using the slider' ); if ( FINGER_TRACKER[ elementID ] === 0 ) { @@ -197,8 +197,8 @@ define( require => { }; // particle engery slider - var sliderWidth = options.minWidth * 0.75; - var particleEnergySlider = new HSlider( alphaParticleEnergyProperty, new Range( + const sliderWidth = options.minWidth * 0.75; + const particleEnergySlider = new HSlider( alphaParticleEnergyProperty, new Range( RSConstants.MIN_ALPHA_ENERGY, RSConstants.MAX_ALPHA_ENERGY ), { @@ -232,20 +232,20 @@ define( require => { // place the slider in a container rectangle so that the layout does not change when the thumb is at the halfway // mark - var thumbWidth = RSConstants.PANEL_SLIDER_THUMB_DIMENSION.width + 2; - var rectHeight = 5; // something small so that it doesn't interfere with the layout - var containerRect = new Rectangle( -thumbWidth / 2, -rectHeight, sliderWidth + thumbWidth, rectHeight ); + const thumbWidth = RSConstants.PANEL_SLIDER_THUMB_DIMENSION.width + 2; + const rectHeight = 5; // something small so that it doesn't interfere with the layout + const containerRect = new Rectangle( -thumbWidth / 2, -rectHeight, sliderWidth + thumbWidth, rectHeight ); containerRect.addChild( particleEnergySlider ); // show traces - var showTraceStrut = new HStrut( options.minWidth * 0.05 ); - var showTraceText = new Text( showTracesString, { + const showTraceStrut = new HStrut( options.minWidth * 0.05 ); + const showTraceText = new Text( showTracesString, { font: RSConstants.PANEL_PROPERTY_FONT, fontWeight: 'bold', fill: RSColorProfile.panelLabelColorProperty, maxWidth: 180 } ); - var showTraceCheckbox = new Checkbox( showTraceText, showTracesProperty, { + const showTraceCheckbox = new Checkbox( showTraceText, showTracesProperty, { checkboxColor: RSColorProfile.panelLabelColorProperty, checkboxColorBackground: RSColorProfile.panelColorProperty, @@ -255,7 +255,7 @@ define( require => { descriptionContent: traceCheckboxDescriptionString, containerTagName: 'div' } ); - var showTraceBox = new HBox( { children: [ showTraceStrut, showTraceCheckbox ] } ); + const showTraceBox = new HBox( { children: [ showTraceStrut, showTraceCheckbox ] } ); VBox.call( this, { spacing: RSConstants.PANEL_CHILD_SPACING, diff --git a/js/common/view/MenuOptionsNode.js b/js/common/view/MenuOptionsNode.js index 30af0d2..90ca348 100644 --- a/js/common/view/MenuOptionsNode.js +++ b/js/common/view/MenuOptionsNode.js @@ -23,7 +23,7 @@ define( require => { */ function MenuOptionsNode() { - var projectorCheckbox = new ProjectorModeCheckbox( RSColorProfile ); + const projectorCheckbox = new ProjectorModeCheckbox( RSColorProfile ); VBox.call( this, _.extend( { children: [ projectorCheckbox ], diff --git a/js/common/view/NuclearParticleLegendPanel.js b/js/common/view/NuclearParticleLegendPanel.js index 595a4a8..2dc7e5c 100644 --- a/js/common/view/NuclearParticleLegendPanel.js +++ b/js/common/view/NuclearParticleLegendPanel.js @@ -49,7 +49,7 @@ define( require => { }, options ); // {Array.} - children for the content, gets wrapped in AlignBoxes in createPanelContent - var content = []; + const content = []; if ( options.includeElectron ) { content.push( ParticleLegendPanel.createParticleBox( ParticleNodeFactory.createElectron(), electronString ) ); } diff --git a/js/common/view/ParticleLegendPanel.js b/js/common/view/ParticleLegendPanel.js index 8593cf4..7fbaed1 100644 --- a/js/common/view/ParticleLegendPanel.js +++ b/js/common/view/ParticleLegendPanel.js @@ -25,7 +25,7 @@ define( require => { const legendString = require( 'string!RUTHERFORD_SCATTERING/legend' ); // constants - var LEGEND_ITEM_HORIZONTAL_SPACING = 12.5; + const LEGEND_ITEM_HORIZONTAL_SPACING = 12.5; /** * @param {VBox} children - content to be contained in the panel @@ -35,7 +35,7 @@ define( require => { function ParticleLegendPanel( content, options ) { // the title for the panel - var legendText = new Text( legendString, { + const legendText = new Text( legendString, { font: RSConstants.PANEL_TITLE_FONT, fontWeight: 'bold', fill: RSColorProfile.panelTitleColorProperty, @@ -43,7 +43,7 @@ define( require => { } ); // title with content, aligned - var contentVBox = new VBox( { + const contentVBox = new VBox( { children: [ legendText, content ], align: 'left', spacing: RSConstants.PANEL_CHILD_SPACING @@ -72,9 +72,9 @@ define( require => { */ function createParticleRow( particleNode, titleString ) { - var hStrut1 = new HStrut( LEGEND_ITEM_HORIZONTAL_SPACING - particleNode.width / 2 ); - var titleText = new Text( titleString, { font: RSConstants.PANEL_PROPERTY_FONT, fill: RSColorProfile.panelLabelColorProperty, maxWidth: 175 } ); - var hStrut2 = new HStrut( LEGEND_ITEM_HORIZONTAL_SPACING - particleNode.width / 2 ); + const hStrut1 = new HStrut( LEGEND_ITEM_HORIZONTAL_SPACING - particleNode.width / 2 ); + const titleText = new Text( titleString, { font: RSConstants.PANEL_PROPERTY_FONT, fill: RSColorProfile.panelLabelColorProperty, maxWidth: 175 } ); + const hStrut2 = new HStrut( LEGEND_ITEM_HORIZONTAL_SPACING - particleNode.width / 2 ); // container for one row in the legend return new HBox( { @@ -135,8 +135,8 @@ define( require => { }, options ); // i18n - make align boxes for all items so that they are the same height, important when strings change size - var alignGroup = new AlignGroup( { matchHorizontal: false } ); - var children = []; + const alignGroup = new AlignGroup( { matchHorizontal: false } ); + const children = []; content.forEach( function( item ) { children.push( alignGroup.createBox( item ) ); } ); diff --git a/js/common/view/ParticleNodeFactory.js b/js/common/view/ParticleNodeFactory.js index e1253ce..99cc761 100644 --- a/js/common/view/ParticleNodeFactory.js +++ b/js/common/view/ParticleNodeFactory.js @@ -20,23 +20,23 @@ define( require => { const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' ); // constants - var SPECULAR_HIGHLITE_COLOR = 'rgb(200,200,200)'; - var ELECTRON_COLOR = 'rgb(135,135,205)'; - var PROTON_COLOR = 'rgb(255,69,0)'; - var NEUTRON_COLOR = 'rgb(192,192,192)'; - var PARTICLE_COLOR = 'rgb(255,0,255)'; - var ENERGY_LEVEL_COLOR = 'rgb(128,128,128)'; - var ELECTRON_RADIUS = 2.5; - var PROTON_RADIUS = 4; - var NEUTRON_RADIUS = 4; - var PARTICLE_RADIUS = 2; - var NUCLEUS_RADIUS = 2; - var ENERGY_LEVEL_LINE_LENGTH = 5; + const SPECULAR_HIGHLITE_COLOR = 'rgb(200,200,200)'; + const ELECTRON_COLOR = 'rgb(135,135,205)'; + const PROTON_COLOR = 'rgb(255,69,0)'; + const NEUTRON_COLOR = 'rgb(192,192,192)'; + const PARTICLE_COLOR = 'rgb(255,0,255)'; + const ENERGY_LEVEL_COLOR = 'rgb(128,128,128)'; + const ELECTRON_RADIUS = 2.5; + const PROTON_RADIUS = 4; + const NEUTRON_RADIUS = 4; + const PARTICLE_RADIUS = 2; + const NUCLEUS_RADIUS = 2; + const ENERGY_LEVEL_LINE_LENGTH = 5; // images const plumPuddingImage = require( 'image!RUTHERFORD_SCATTERING/plumPuddingIcon.png' ); - var ParticleNodeFactory = { + const ParticleNodeFactory = { /** * Creates an electron node. @@ -225,7 +225,7 @@ define( require => { context.arc( x, y, radius, 0, 2 * Math.PI, false); // create the radial gradient from the center of the arc - var gradient = context.createRadialGradient( x + radius * 0.1, y + radius * 0.7, 0.2, x + -radius * 0.2, y + -radius * 0.3, radius * 2 ); + const gradient = context.createRadialGradient( x + radius * 0.1, y + radius * 0.7, 0.2, x + -radius * 0.2, y + -radius * 0.3, radius * 2 ); gradient.addColorStop( 0, SPECULAR_HIGHLITE_COLOR ); gradient.addColorStop( 0.33, color ); gradient.addColorStop( 1, 'black' ); diff --git a/js/common/view/ParticleSpaceNode.js b/js/common/view/ParticleSpaceNode.js index d6ab83d..4820a46 100644 --- a/js/common/view/ParticleSpaceNode.js +++ b/js/common/view/ParticleSpaceNode.js @@ -24,10 +24,10 @@ define( require => { const Util = require( 'DOT/Util' ); // constants - var SPACE_BORDER_WIDTH = 2; - var SPACE_BORDER_COLOR = 'grey'; - var PARTICLE_TRACE_WIDTH = 1.5; - var FADEOUT_SEGMENTS = 80; + const SPACE_BORDER_WIDTH = 2; + const SPACE_BORDER_COLOR = 'grey'; + const PARTICLE_TRACE_WIDTH = 1.5; + const FADEOUT_SEGMENTS = 80; /** * @param {atomSpace} atomSpace - space containing atoms and particles @@ -52,7 +52,7 @@ define( require => { CanvasNode.call( this, options ); - var self = this; + const self = this; // @private this.atomSpace = atomSpace; @@ -78,7 +78,7 @@ define( require => { }; // create a single alpha particle image to use for rendering all particles - asynchronous - var alphaParticle; + let alphaParticle; if ( this.particleStyle === 'nucleus' ) { alphaParticle = ParticleNodeFactory.createNucleusAlpha(); } @@ -114,10 +114,10 @@ define( require => { */ paintCanvas: function( context ) { - var self = this; + const self = this; - var bounds = this.canvasBounds; - var renderTrace = self.showAlphaTraceProperty.value; + const bounds = this.canvasBounds; + const renderTrace = self.showAlphaTraceProperty.value; // clear context.clearRect( bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() ); @@ -158,7 +158,7 @@ define( require => { * @private */ renderAlphaParticles: function( context, particleContainer, renderTrace ) { - var self = this; + const self = this; if ( renderTrace ) { @@ -176,24 +176,24 @@ define( require => { if ( renderTrace ) { // add trace segments - for ( var i = 1; i < particle.positions.length; i++ ) { + for ( let i = 1; i < particle.positions.length; i++ ) { if ( self.particleStyle === 'particle' ) { // if the style is of a 'particle', each segment needs a new path to create the gradient effect context.beginPath(); } - var segmentStartViewPosition = self.modelViewTransform.modelToViewPosition( particle.positions[ i - 1 ] ); + const segmentStartViewPosition = self.modelViewTransform.modelToViewPosition( particle.positions[ i - 1 ] ); context.moveTo( segmentStartViewPosition.x, segmentStartViewPosition.y ); - var segmentEndViewPosition = self.modelViewTransform.modelToViewPosition( particle.positions[ i ] ); + const segmentEndViewPosition = self.modelViewTransform.modelToViewPosition( particle.positions[ i ] ); context.lineTo( segmentEndViewPosition.x, segmentEndViewPosition.y ); if ( self.particleStyle === 'particle' ) { // only the last FADEOUT_SEGMENTS should be visible, map i to the opacity - var length = particle.positions.length; - var alpha = Util.linear( length - FADEOUT_SEGMENTS, length, 0, 0.5, i ); - var strokeStyle = StringUtils.format( self.particleTraceColorWithFade, alpha ); + const length = particle.positions.length; + const alpha = Util.linear( length - FADEOUT_SEGMENTS, length, 0, 0.5, i ); + const strokeStyle = StringUtils.format( self.particleTraceColorWithFade, alpha ); context.strokeStyle = strokeStyle; context.stroke(); context.closePath(); @@ -202,7 +202,7 @@ define( require => { } // render particle - var particleViewPosition = self.modelViewTransform.modelToViewPosition( particle.positionProperty.get() ); + const particleViewPosition = self.modelViewTransform.modelToViewPosition( particle.positionProperty.get() ); context.drawImage( self.alphaParticleImage, particleViewPosition.x - self.particleImageHalfWidth, particleViewPosition.y - self.particleImageHalfHeight ); diff --git a/js/common/view/RSBaseScreenView.js b/js/common/view/RSBaseScreenView.js index 5ebdf5b..afe5fb3 100644 --- a/js/common/view/RSBaseScreenView.js +++ b/js/common/view/RSBaseScreenView.js @@ -39,14 +39,14 @@ define( require => { const alphaParticlesString = require( 'string!RUTHERFORD_SCATTERING/alphaParticles' ); // a11y strings - var toggleAlphaParticleString = RSA11yStrings.toggleAlphaParticle.value; - var alphaParticlesHelpTextString = RSA11yStrings.alphaParticlesHelpText.value; + const toggleAlphaParticleString = RSA11yStrings.toggleAlphaParticle.value; + const alphaParticlesHelpTextString = RSA11yStrings.alphaParticlesHelpText.value; - var otherViewingStreamingOptionsString = RSA11yStrings.otherViewingStreamingOptions.value; - var otherOptionsDescriptionString = RSA11yStrings.otherOptionsDescription.value; + const otherViewingStreamingOptionsString = RSA11yStrings.otherViewingStreamingOptions.value; + const otherOptionsDescriptionString = RSA11yStrings.otherOptionsDescription.value; // constants - var GUN_ROTATION = -Math.PI / 2; // so the laser pointer points straight up + const GUN_ROTATION = -Math.PI / 2; // so the laser pointer points straight up /** * @param {RSBaseModel} model @@ -67,7 +67,7 @@ define( require => { }, options ); ScreenView.call( this, options ); - var self = this; + const self = this; // properties this.showAlphaTraceProperty = new Property( RSConstants.DEFAULT_SHOW_TRACES ); @@ -89,7 +89,7 @@ define( require => { } ); this.addChild( this.gunNode ); - var alphaParticlesText = new Text( alphaParticlesString, { + const alphaParticlesText = new Text( alphaParticlesString, { centerX: this.gunNode.centerX, top: this.gunNode.bottom + 15, font: new PhetFont( 15 ), @@ -114,26 +114,26 @@ define( require => { this.addChild( this.targetMaterialNode ); // tiny box that indicates what will be zoomed - var tinyBoxNode = new TinyBox( { + const tinyBoxNode = new TinyBox( { centerX: self.targetMaterialNode.centerX, centerY: self.targetMaterialNode.centerY } ); this.addChild( tinyBoxNode ); // atom animation space - var spaceNodeX = this.targetMaterialNode.right + RSConstants.TARGET_SPACE_MARGIN - RSConstants.SPACE_BUFFER; - var spaceNodeY = RSConstants.PANEL_TOP_MARGIN - RSConstants.SPACE_BUFFER; - var spaceNodeBounds = new Bounds2( spaceNodeX, spaceNodeY, + const spaceNodeX = this.targetMaterialNode.right + RSConstants.TARGET_SPACE_MARGIN - RSConstants.SPACE_BUFFER; + const spaceNodeY = RSConstants.PANEL_TOP_MARGIN - RSConstants.SPACE_BUFFER; + const spaceNodeBounds = new Bounds2( spaceNodeX, spaceNodeY, spaceNodeX + RSConstants.SPACE_NODE_WIDTH, spaceNodeY + RSConstants.SPACE_NODE_HEIGHT ); - var modelViewTransform = new ModelViewTransform2.createRectangleInvertedYMapping( model.bounds, spaceNodeBounds ); + const modelViewTransform = new ModelViewTransform2.createRectangleInvertedYMapping( model.bounds, spaceNodeBounds ); // @protected for layout in subtypes this.spaceNode = createSpaceNode( model, this.showAlphaTraceProperty, modelViewTransform, spaceNodeBounds ); this.addChild( this.spaceNode ); // dashed lines that connect the tiny box and space - var dashedLines = new Path( new Shape() + const dashedLines = new Path( new Shape() .moveTo( tinyBoxNode.centerX, tinyBoxNode.top ) .lineTo( self.spaceNode.left, self.spaceNode.top ) .moveTo( tinyBoxNode.centerX, tinyBoxNode.bottom ) @@ -151,7 +151,7 @@ define( require => { this.addChild( this.scaleInfoNode ); // play/pause button - var playPauseButton = new PlayPauseButton( model.runningProperty, { + const playPauseButton = new PlayPauseButton( model.runningProperty, { bottom: this.scaleInfoNode.bottom + 60, centerX: this.scaleInfoNode.centerX - 25, radius: 23 @@ -159,7 +159,7 @@ define( require => { this.addChild( playPauseButton ); // step button to manually step the animation. - var stepButton = new StepForwardButton( { + const stepButton = new StepForwardButton( { isPlayingProperty: model.runningProperty, listener: function() { model.manualStep(); }, centerY: playPauseButton.centerY, @@ -169,7 +169,7 @@ define( require => { this.addChild( stepButton ); // reset all button - var resetAllButton = new ResetAllButton( { + const resetAllButton = new ResetAllButton( { listener: function() { self.showAlphaTraceProperty.reset(); model.reset(); @@ -180,7 +180,7 @@ define( require => { this.addChild( resetAllButton ); // a11y - var viewingStreamingOptionsNode = new Node( { + const viewingStreamingOptionsNode = new Node( { tagName: 'div', labelTagName: 'h3', labelContent: otherViewingStreamingOptionsString, diff --git a/js/common/view/RSControlPanel.js b/js/common/view/RSControlPanel.js index 9310fc2..d09a368 100644 --- a/js/common/view/RSControlPanel.js +++ b/js/common/view/RSControlPanel.js @@ -27,7 +27,7 @@ define( require => { Node.call( this ); - var defaultOptions = { + const defaultOptions = { spacing: RSConstants.PANEL_VERTICAL_MARGIN, align: 'left', resize: false, @@ -36,7 +36,7 @@ define( require => { this.panelOptions = _.extend( defaultOptions, options ); // @private // @private - arrange control panels vertically - var vBox = new VBox( this.panelOptions ); + const vBox = new VBox( this.panelOptions ); this.addChild( vBox ); this.mutate( options ); diff --git a/js/common/view/RSScreenSummaryNode.js b/js/common/view/RSScreenSummaryNode.js index affd04b..aac3fda 100644 --- a/js/common/view/RSScreenSummaryNode.js +++ b/js/common/view/RSScreenSummaryNode.js @@ -14,7 +14,7 @@ define( require => { const RSA11yStrings = require( 'RUTHERFORD_SCATTERING/common/RSA11yStrings' ); const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' ); - var screenSummaryString = RSA11yStrings.screenSummary.value; + const screenSummaryString = RSA11yStrings.screenSummary.value; /** * @constructor diff --git a/js/common/view/ScaleInfoNode.js b/js/common/view/ScaleInfoNode.js index d256759..647cda2 100644 --- a/js/common/view/ScaleInfoNode.js +++ b/js/common/view/ScaleInfoNode.js @@ -21,9 +21,9 @@ define( require => { const Shape = require( 'KITE/Shape' ); // constants - var ARROW_HEAD_WIDTH = 12; - var ARROW_HEAD_HEIGHT = 12; - var ARROW_TAIL_MARGIN = 5; + const ARROW_HEAD_WIDTH = 12; + const ARROW_HEAD_HEIGHT = 12; + const ARROW_TAIL_MARGIN = 5; /** * @param {string} label - the label to place in the middle of the arrows @@ -38,16 +38,16 @@ define( require => { }, options ); // scale text - var labelText = new RichText( label, { + const labelText = new RichText( label, { font: options.font, fill: RSColorProfile.panelLabelColorProperty, maxWidth: 0.9 * width } ); // left arrow - var arrowWidth = ( width - labelText.getWidth() ) / 2; - var leftArrowX = labelText.left - arrowWidth; - var leftArrowNode = new ArrowNode( labelText.left - ARROW_TAIL_MARGIN, labelText.centerY, + const arrowWidth = ( width - labelText.getWidth() ) / 2; + const leftArrowX = labelText.left - arrowWidth; + const leftArrowNode = new ArrowNode( labelText.left - ARROW_TAIL_MARGIN, labelText.centerY, leftArrowX, labelText.centerY, { headHeight: ARROW_HEAD_HEIGHT, headWidth: ARROW_HEAD_WIDTH, @@ -56,8 +56,8 @@ define( require => { } ); // right arrow - var rightArrowX = labelText.right + arrowWidth; - var rightArrowNode = new ArrowNode( labelText.right + ARROW_TAIL_MARGIN, labelText.centerY, + const rightArrowX = labelText.right + arrowWidth; + const rightArrowNode = new ArrowNode( labelText.right + ARROW_TAIL_MARGIN, labelText.centerY, rightArrowX, labelText.centerY, { headHeight: ARROW_HEAD_HEIGHT, headWidth: ARROW_HEAD_WIDTH, @@ -66,12 +66,12 @@ define( require => { } ); // end markers - var leftMarker = new Path( new Shape().moveTo( leftArrowX, labelText.bounds.minY ).lineTo( leftArrowX, labelText.bounds.maxY ), { + const leftMarker = new Path( new Shape().moveTo( leftArrowX, labelText.bounds.minY ).lineTo( leftArrowX, labelText.bounds.maxY ), { stroke: RSColorProfile.panelLabelColorProperty, lineWidth: 1.5 } ); - var rightMarker = new Path( new Shape().moveTo( rightArrowX, labelText.bounds.minY ).lineTo( rightArrowX, labelText.bounds.maxY ), { + const rightMarker = new Path( new Shape().moveTo( rightArrowX, labelText.bounds.minY ).lineTo( rightArrowX, labelText.bounds.maxY ), { stroke: RSColorProfile.panelLabelColorProperty, lineWidth: 1.5 } ); diff --git a/js/common/view/TargetMaterialNode.js b/js/common/view/TargetMaterialNode.js index a8b7511..91807f6 100644 --- a/js/common/view/TargetMaterialNode.js +++ b/js/common/view/TargetMaterialNode.js @@ -18,11 +18,11 @@ define( require => { const Shape = require( 'KITE/Shape' ); // constants - var BACK_DEPTH = 30; - var BACK_OFFSET = 0.10; - var BOX_SIZE = new Dimension2( 120, 120 ); - var BACK_COLOR = '#8c7e29'; - var FRONT_COLOR = '#d6cb86'; + const BACK_DEPTH = 30; + const BACK_OFFSET = 0.10; + const BOX_SIZE = new Dimension2( 120, 120 ); + const BACK_COLOR = '#8c7e29'; + const FRONT_COLOR = '#d6cb86'; /** * @param {Object} [options] @@ -33,7 +33,7 @@ define( require => { options = options || {}; // top face, in perspective - var topNode = new Path( new Shape() + const topNode = new Path( new Shape() .moveTo( BACK_OFFSET * BOX_SIZE.width, 0 ) .lineTo( ( 1 - BACK_OFFSET ) * BOX_SIZE.width, 0 ) .lineTo( BOX_SIZE.width, BACK_DEPTH ) diff --git a/js/common/view/TinyBox.js b/js/common/view/TinyBox.js index c756f14..d84f1b9 100644 --- a/js/common/view/TinyBox.js +++ b/js/common/view/TinyBox.js @@ -17,9 +17,9 @@ define( require => { const Shape = require( 'KITE/Shape' ); // constants - var BACK_DEPTH = 4; - var BACK_OFFSET = 0.10; - var BOX_SIZE = new Dimension2( 10, 10 ); + const BACK_DEPTH = 4; + const BACK_OFFSET = 0.10; + const BOX_SIZE = new Dimension2( 10, 10 ); /** * @param {Object} [options] @@ -33,7 +33,7 @@ define( require => { lineWidth: 1 }, options ); - var topNode = new Path( new Shape() + const topNode = new Path( new Shape() .moveTo( BACK_OFFSET * BOX_SIZE.width, 0 ) .lineTo( ( 1 - BACK_OFFSET ) * BOX_SIZE.width, 0 ) .lineTo( BOX_SIZE.width, BACK_DEPTH ) diff --git a/js/plumpuddingatom/PlumPuddingAtomScreen.js b/js/plumpuddingatom/PlumPuddingAtomScreen.js index ef3c5ea..2abce19 100644 --- a/js/plumpuddingatom/PlumPuddingAtomScreen.js +++ b/js/plumpuddingatom/PlumPuddingAtomScreen.js @@ -28,7 +28,7 @@ define( require => { */ function PlumPuddingAtomScreen() { - var options = { + const options = { name: plumPuddingAtomString, backgroundColorProperty: RSColorProfile.backgroundColorProperty, homeScreenIcon: new Image( screenIcon ) diff --git a/js/plumpuddingatom/view/PlumPuddingAtomScreenView.js b/js/plumpuddingatom/view/PlumPuddingAtomScreenView.js index 8b28a57..78b6be9 100644 --- a/js/plumpuddingatom/view/PlumPuddingAtomScreenView.js +++ b/js/plumpuddingatom/view/PlumPuddingAtomScreenView.js @@ -28,16 +28,16 @@ define( require => { */ function PlumPuddingAtomScreenView( model ) { - var scaleString = StringUtils.format( pattern0AtomicScaleString, '3.0 x 10-10' ); + const scaleString = StringUtils.format( pattern0AtomicScaleString, '3.0 x 10-10' ); RSBaseScreenView.call( this, model, scaleString, createSpaceNode, { includePlumPuddingLegend: true } ); // create the new control panel - var propertiesPanelContent = AlphaParticlePropertiesPanel.createPanelContent( model.userInteractionProperty, + const propertiesPanelContent = AlphaParticlePropertiesPanel.createPanelContent( model.userInteractionProperty, model.alphaParticleEnergyProperty, this.showAlphaTraceProperty, { resize: false } ); - var legendPanelContent = NuclearParticleLegendPanel.createPanelContent( { + const legendPanelContent = NuclearParticleLegendPanel.createPanelContent( { resize: false, includeElectron: true, includePlumPudding: true @@ -45,14 +45,14 @@ define( require => { // handle alignment for the panels, should have exactly the same width, but the legend content should be aligned // to the left - var contentAlignGroup = new AlignGroup( { matchVertical: false } ); - var particleContentBox = contentAlignGroup.createBox( propertiesPanelContent ); - var legendContentBox = contentAlignGroup.createBox( legendPanelContent, { xAlign: ParticleLegendPanel.LEGEND_CONTENT_ALIGN } ); + const contentAlignGroup = new AlignGroup( { matchVertical: false } ); + const particleContentBox = contentAlignGroup.createBox( propertiesPanelContent ); + const legendContentBox = contentAlignGroup.createBox( legendPanelContent, { xAlign: ParticleLegendPanel.LEGEND_CONTENT_ALIGN } ); - var particlePropertiesPanel = new AlphaParticlePropertiesPanel( particleContentBox, { resize: false } ); - var legendPanel = new NuclearParticleLegendPanel( legendContentBox, { resize: false } ); + const particlePropertiesPanel = new AlphaParticlePropertiesPanel( particleContentBox, { resize: false } ); + const legendPanel = new NuclearParticleLegendPanel( legendContentBox, { resize: false } ); - var panels = [ + const panels = [ legendPanel, particlePropertiesPanel ]; @@ -77,7 +77,7 @@ define( require => { * @returns {Node} */ var createSpaceNode = function( model, showAlphaTraceProperty, modelViewTransform, canvasBounds ) { - var plumPuddingSpaceNode = new PlumPuddingSpaceNode( model, showAlphaTraceProperty, modelViewTransform, { + const plumPuddingSpaceNode = new PlumPuddingSpaceNode( model, showAlphaTraceProperty, modelViewTransform, { canvasBounds: canvasBounds } ); diff --git a/js/plumpuddingatom/view/PlumPuddingSpaceNode.js b/js/plumpuddingatom/view/PlumPuddingSpaceNode.js index 445d943..58c73f7 100644 --- a/js/plumpuddingatom/view/PlumPuddingSpaceNode.js +++ b/js/plumpuddingatom/view/PlumPuddingSpaceNode.js @@ -34,12 +34,12 @@ define( require => { // plum pudding image - calc image scale and center positioning this.atomNode = new PlumPuddingAtomNode(); - var scale = Math.min( this.width, this.height ) / + const scale = Math.min( this.width, this.height ) / ( Math.max( this.atomNode.width, this.atomNode.height ) ); - var imageWidth = this.atomNode.width * scale; - var imageHeight = this.atomNode.height * scale; - var imageX = this.bounds.centerX - imageWidth / 2; - var imageY = this.bounds.centerY - imageHeight / 2; + const imageWidth = this.atomNode.width * scale; + const imageHeight = this.atomNode.height * scale; + const imageX = this.bounds.centerX - imageWidth / 2; + const imageY = this.bounds.centerY - imageHeight / 2; this.atomNodeRect = { x: imageX, y: imageY, width: imageWidth, height: imageHeight }; this.invalidatePaint(); diff --git a/js/rutherford-scattering-main.js b/js/rutherford-scattering-main.js index 31ebdd0..f385d32 100644 --- a/js/rutherford-scattering-main.js +++ b/js/rutherford-scattering-main.js @@ -20,7 +20,7 @@ define( require => { // strings const rutherfordScatteringTitleString = require( 'string!RUTHERFORD_SCATTERING/rutherford-scattering.title' ); - var simOptions = { + const simOptions = { credits: { leadDesign: 'Amy Hanson, Sam McKagan', softwareDevelopment: 'Jesse Greenberg, Chris Malley, Dave Schmitz', @@ -40,11 +40,11 @@ define( require => { FocusOverlay.setOuterGroupHighlightColor( RSColorProfile.outerGroupHighlightColorProperty ); SimLauncher.launch( function() { - var screens = [ + const screens = [ new RutherfordAtomScreen(), new PlumPuddingAtomScreen() ]; - var sim = new Sim( rutherfordScatteringTitleString, screens, simOptions ); + const sim = new Sim( rutherfordScatteringTitleString, screens, simOptions ); sim.start(); } ); } ); diff --git a/js/rutherfordatom/RutherfordAtomScreen.js b/js/rutherfordatom/RutherfordAtomScreen.js index 079ae08..c1a4bb1 100644 --- a/js/rutherfordatom/RutherfordAtomScreen.js +++ b/js/rutherfordatom/RutherfordAtomScreen.js @@ -28,13 +28,13 @@ define( require => { function RutherfordAtomScreen() { // create an icon for the rutherford atom screen with default number of protons and neutrons - var homeScreenIcon = new ScreenIcon( RutherfordNucleusNode.RutherfordNucleusIcon( + const homeScreenIcon = new ScreenIcon( RutherfordNucleusNode.RutherfordNucleusIcon( RSConstants.DEFAULT_PROTON_COUNT, RSConstants.DEFAULT_NEUTRON_COUNT ), { fill: RSColorProfile.screenIconFillColorProperty } ); - var options = { + const options = { name: rutherfordAtomString, backgroundColorProperty: RSColorProfile.backgroundColorProperty, homeScreenIcon: homeScreenIcon diff --git a/js/rutherfordatom/model/RutherfordAtom.js b/js/rutherfordatom/model/RutherfordAtom.js index af1a2af..b74d1e0 100644 --- a/js/rutherfordatom/model/RutherfordAtom.js +++ b/js/rutherfordatom/model/RutherfordAtom.js @@ -87,53 +87,53 @@ define( require => { // apply a rotation to the particle coordinate frame if nececssary so that // the trajectory algorithm can proceed as if the particle were moving straight // up the space - this is required by the trajectory model, see trajectories.pdf - var rotationAngle = alphaParticle.rotationAngle; - var correctedInitialPosition = this.rotatePointAround( alphaParticle.initialPosition, this.position, -rotationAngle ); - var correctedPosition = this.rotatePointAround( alphaParticle.positionProperty.get(), this.position, -rotationAngle ); + const rotationAngle = alphaParticle.rotationAngle; + const correctedInitialPosition = this.rotatePointAround( alphaParticle.initialPosition, this.position, -rotationAngle ); + const correctedPosition = this.rotatePointAround( alphaParticle.positionProperty.get(), this.position, -rotationAngle ); // algorithm fails for x=0, so use this min value - var X0_MIN = 0.00001; + const X0_MIN = 0.00001; // Divisor for L used in the calculation of D. - var L_DIVISOR = 8; + const L_DIVISOR = 8; //------------------------------------------------------------------------------- // misc constants that we'll need //------------------------------------------------------------------------------- - var L = this.boundingRect.bounds.getWidth(); + const L = this.boundingRect.bounds.getWidth(); - var p = this.protonCountProperty.get(); // protons in the atom's nucleus - var pd = RSConstants.DEFAULT_PROTON_COUNT; // default setting for the sim + const p = this.protonCountProperty.get(); // protons in the atom's nucleus + const pd = RSConstants.DEFAULT_PROTON_COUNT; // default setting for the sim - var s = alphaParticle.speedProperty.get(); // particle's current speed - var s0 = alphaParticle.speedProperty.initialValue; // speed when it left the gun - var sd = RSConstants.DEFAULT_ALPHA_ENERGY; // default setting for the sim + const s = alphaParticle.speedProperty.get(); // particle's current speed + const s0 = alphaParticle.speedProperty.initialValue; // speed when it left the gun + const sd = RSConstants.DEFAULT_ALPHA_ENERGY; // default setting for the sim //------------------------------------------------------------------------------- // (x0,y0) : the alpha particle's initial position, relative to the atom's center. //------------------------------------------------------------------------------- // var initialPosition = alphaParticle.initialPosition; - var relativeInitialPosition = correctedInitialPosition.minus( this.position ); + const relativeInitialPosition = correctedInitialPosition.minus( this.position ); - var x0 = Math.abs( relativeInitialPosition.x ); + let x0 = Math.abs( relativeInitialPosition.x ); if ( x0 < X0_MIN ) { x0 = X0_MIN; // algorithm fails for x0 < X0_MIN } - var y0 = relativeInitialPosition.y; + const y0 = relativeInitialPosition.y; //------------------------------------------------------------------------------- // (x,y) : the alpha particle's current position, relative to the atom's center //------------------------------------------------------------------------------- // var position = alphaParticle.positionProperty.get(); - var relativePosition = correctedPosition.minus( this.position ); + const relativePosition = correctedPosition.minus( this.position ); - var x = relativePosition.x; - var y = relativePosition.y; - var xWasNegative = false; + let x = relativePosition.x; + const y = relativePosition.y; + let xWasNegative = false; if ( x < 0 ) { // This algorithm fails for x < 0, so adjust accordingly. x *= -1; @@ -150,79 +150,79 @@ define( require => { return; } - var D = ( L / L_DIVISOR ) * ( p / pd ) * ( ( sd * sd ) / ( s0 * s0 ) ); + const D = ( L / L_DIVISOR ) * ( p / pd ) * ( ( sd * sd ) / ( s0 * s0 ) ); //------------------------------------------------------------------------------- // calculate new alpha particle position, in Polar coordinates //------------------------------------------------------------------------------- // check intermediate values to handle potential algorithm failures - var i0 = ( x0 * x0 ) + ( y0 * y0 ); + const i0 = ( x0 * x0 ) + ( y0 * y0 ); if ( i0 < 0 ) { this.removeParticle( alphaParticle, true, '162' ); return; } // b, horizontal distance to atom's center at y == negative infinity - var b1 = Math.sqrt( i0 ); + const b1 = Math.sqrt( i0 ); // check intermediate values to handle potential algorithm failures - var i1 = ( -2 * D * b1 ) - ( 2 * D * y0 ) + ( x0 * x0 ); + const i1 = ( -2 * D * b1 ) - ( 2 * D * y0 ) + ( x0 * x0 ); if ( i1 < 0 ) { this.removeParticle( alphaParticle, true, '172' ); return; } - var b = 0.5 * ( x0 + Math.sqrt( i1 ) ); + const b = 0.5 * ( x0 + Math.sqrt( i1 ) ); // convert current position to Polar coordinates, measured counterclockwise from the -y axis // check intermediate values to handle potential algorithm failures - var i2 = ( x * x ) + ( y * y ); + const i2 = ( x * x ) + ( y * y ); if ( i2 < 0 ) { this.removeParticle( alphaParticle, true, '183' ); return; } - var r = Math.sqrt( i2 ); - var phi = Math.atan2( x, -y ); + const r = Math.sqrt( i2 ); + const phi = Math.atan2( x, -y ); // new position (in Polar coordinates) and speed - var t1 = ( ( b * Math.cos( phi ) ) - ( ( D / 2 ) * Math.sin( phi ) ) ); + const t1 = ( ( b * Math.cos( phi ) ) - ( ( D / 2 ) * Math.sin( phi ) ) ); // check intermediate values to handle potential algorithm failures - var i3 = Math.pow( b, 4 ) + ( r * r * t1 * t1 ); + const i3 = Math.pow( b, 4 ) + ( r * r * t1 * t1 ); if ( i3 < 0 ) { this.removeParticle( alphaParticle, true, '196' ); return; } - var phiNew = phi + ( ( b * b * s * dt ) / ( r * Math.sqrt( i3 ) ) ); + const phiNew = phi + ( ( b * b * s * dt ) / ( r * Math.sqrt( i3 ) ) ); // check intermediate values to handle potential algorithm failures - var i4 = ( ( b * Math.sin( phiNew ) ) + ( ( D / 2 ) * ( Math.cos( phiNew ) - 1 ) ) ); + const i4 = ( ( b * Math.sin( phiNew ) ) + ( ( D / 2 ) * ( Math.cos( phiNew ) - 1 ) ) ); if ( i4 < 0 ) { this.removeParticle( alphaParticle, true, '204' ); return; } - var rNew = Math.abs( ( b * b ) / i4 ); + const rNew = Math.abs( ( b * b ) / i4 ); // handle potential algorithm failures if ( rNew === 0 ) { this.removeParticle( alphaParticle, true, '211' ); return; } - var sNew = s0 * Math.sqrt( 1 - ( D / rNew ) ); + const sNew = s0 * Math.sqrt( 1 - ( D / rNew ) ); //------------------------------------------------------------------------------- // convert to Cartesian coordinates //------------------------------------------------------------------------------- - var xNew = rNew * Math.sin( phiNew ); + let xNew = rNew * Math.sin( phiNew ); if ( xWasNegative ) { xNew *= -1; // restore the sign } - var yNew = -rNew * Math.cos( phiNew ); + const yNew = -rNew * Math.cos( phiNew ); //------------------------------------------------------------------------------- // handle potential algorithm failures @@ -238,7 +238,7 @@ define( require => { //------------------------------------------------------------------------------- // get the change in position relative to the atom's center, and rotate back to space coordinates - var delta = new Vector2( xNew, yNew ).minus( relativePosition ); + const delta = new Vector2( xNew, yNew ).minus( relativePosition ); delta.rotate( alphaParticle.rotationAngle ); // update the position of the particle in its space coordinates @@ -260,15 +260,15 @@ define( require => { */ rotatePointAround: function( point, rotatePoint, angle ) { - var sinAngle = Math.sin( angle ); - var cosAngle = Math.cos( angle ); + const sinAngle = Math.sin( angle ); + const cosAngle = Math.cos( angle ); // translate the point back to the origin by subtracting the pivot point - var translatedPosition = point.minus( rotatePoint ); + const translatedPosition = point.minus( rotatePoint ); // rotate the point with the equivalent rotation matrix - var xNew = translatedPosition.x * cosAngle - translatedPosition.y * sinAngle; - var yNew = translatedPosition.x * sinAngle + translatedPosition.y * cosAngle; + const xNew = translatedPosition.x * cosAngle - translatedPosition.y * sinAngle; + const yNew = translatedPosition.x * sinAngle + translatedPosition.y * cosAngle; // translate the point back return new Vector2( xNew, yNew ).plus( rotatePoint ); diff --git a/js/rutherfordatom/model/RutherfordAtomSpace.js b/js/rutherfordatom/model/RutherfordAtomSpace.js index 637c369..37a481f 100644 --- a/js/rutherfordatom/model/RutherfordAtomSpace.js +++ b/js/rutherfordatom/model/RutherfordAtomSpace.js @@ -16,7 +16,7 @@ define( require => { const Vector2 = require( 'DOT/Vector2' ); // constants - var DEFLECTION_WIDTH = 30; + const DEFLECTION_WIDTH = 30; /** * Constructor. @@ -30,15 +30,15 @@ define( require => { } ); // factor out for readability - var atomWidth = this.bounds.width / 2; // bounds of the entire atom, including electron radii - var halfAtomWidth = atomWidth / 2; + const atomWidth = this.bounds.width / 2; // bounds of the entire atom, including electron radii + const halfAtomWidth = atomWidth / 2; // create the atoms - var atom1 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( -halfAtomWidth, +halfAtomWidth ), DEFLECTION_WIDTH ); - var atom2 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( +halfAtomWidth, +halfAtomWidth ), DEFLECTION_WIDTH ); - var atom3 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( 0, -halfAtomWidth ), DEFLECTION_WIDTH ); - var atom4 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( -atomWidth, -halfAtomWidth ), DEFLECTION_WIDTH ); - var atom5 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( atomWidth, -halfAtomWidth ), DEFLECTION_WIDTH ); + const atom1 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( -halfAtomWidth, +halfAtomWidth ), DEFLECTION_WIDTH ); + const atom2 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( +halfAtomWidth, +halfAtomWidth ), DEFLECTION_WIDTH ); + const atom3 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( 0, -halfAtomWidth ), DEFLECTION_WIDTH ); + const atom4 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( -atomWidth, -halfAtomWidth ), DEFLECTION_WIDTH ); + const atom5 = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( atomWidth, -halfAtomWidth ), DEFLECTION_WIDTH ); this.atoms.push( atom1, atom2, atom3, atom4, atom5 ); diff --git a/js/rutherfordatom/model/RutherfordNucleus.js b/js/rutherfordatom/model/RutherfordNucleus.js index 77675ed..62eae0b 100644 --- a/js/rutherfordatom/model/RutherfordNucleus.js +++ b/js/rutherfordatom/model/RutherfordNucleus.js @@ -26,13 +26,13 @@ define( require => { ParticleAtom.call( this, { nucleonRadius: 3 } ); - var self = this; - var particle; + const self = this; + let particle; // update number of nucleons of a particular type and move all to destination - var configureNucleus = function( nucleonCount, particleType ) { - var particleCount = Util.toFixedNumber( nucleonCount, 0 ); - var nucleons = particleType === 'proton' ? self.protons : self.neutrons; + const configureNucleus = function( nucleonCount, particleType ) { + const particleCount = Util.toFixedNumber( nucleonCount, 0 ); + const nucleons = particleType === 'proton' ? self.protons : self.neutrons; while( nucleons.length !== particleCount ) { if ( particleCount - nucleons.length > 0 ) { particle = new Particle( particleType ); @@ -46,8 +46,8 @@ define( require => { self.moveAllParticlesToDestination(); }; - var protonObserver = function( protonCount ) { configureNucleus( protonCount, 'proton' ); }; - var neutronObserver = function( neutronCount ) { configureNucleus( neutronCount, 'neutron' ); }; + const protonObserver = function( protonCount ) { configureNucleus( protonCount, 'proton' ); }; + const neutronObserver = function( neutronCount ) { configureNucleus( neutronCount, 'neutron' ); }; protonCountProperty.link( protonObserver ); neutronCountProperty.link( neutronObserver ); diff --git a/js/rutherfordatom/model/RutherfordNucleusSpace.js b/js/rutherfordatom/model/RutherfordNucleusSpace.js index 08de755..df24d52 100644 --- a/js/rutherfordatom/model/RutherfordNucleusSpace.js +++ b/js/rutherfordatom/model/RutherfordNucleusSpace.js @@ -29,7 +29,7 @@ define( require => { // create a nucleus model containing protons and neutrons this.rutherfordNucleus = new RutherfordNucleus( protonCountProperty, neutronCountProperty ); - var rutherfordAtom = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( 0, 0 ), this.bounds.width ); + const rutherfordAtom = new RutherfordAtom( this.particleRemovedFromAtomEmitter, protonCountProperty, new Vector2( 0, 0 ), this.bounds.width ); this.atoms.push( rutherfordAtom ); // make sure that atom bounds are OK diff --git a/js/rutherfordatom/view/AtomCollectionNode.js b/js/rutherfordatom/view/AtomCollectionNode.js index 0907de1..bf157c3 100644 --- a/js/rutherfordatom/view/AtomCollectionNode.js +++ b/js/rutherfordatom/view/AtomCollectionNode.js @@ -22,9 +22,9 @@ define( require => { const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' ); // constants - var IONIZATION_ENERGY = 13.6; // energy required to ionize hydrogen, in eV - var RADIUS_SCALE = 5.95; // scale to make the radii visible in the space, chosen empirically - var ENERGY_LEVELS = 6; // number of energy levels/radii to show for the atom + const IONIZATION_ENERGY = 13.6; // energy required to ionize hydrogen, in eV + const RADIUS_SCALE = 5.95; // scale to make the radii visible in the space, chosen empirically + const ENERGY_LEVELS = 6; // number of energy levels/radii to show for the atom /** * Constructor. @@ -37,50 +37,50 @@ define( require => { function AtomCollectionNode( atomSpace, modelViewTransform, options ) { Node.call( this, options ); - var self = this; + const self = this; // @public (read-only) {null|HTMLImageElement} - This node will eventually be drawn with canvas with // context.drawImage. The image is created asynchronously in this constructor. this.image = null; // draw each atom in the space - called every time the color profile changes - var drawAtomCollection = function() { + const drawAtomCollection = function() { // remove the all children self.removeAllChildren(); atomSpace.atoms.forEach( function( atom ) { // a small circle represents each nucleus - var nucleusCircle = ParticleNodeFactory.createNucleus(); + const nucleusCircle = ParticleNodeFactory.createNucleus(); nucleusCircle.center = modelViewTransform.modelToViewPosition( atom.position ); self.addChild( nucleusCircle ); // create the radii - concentric circles with dashed lines spaced proportionally to the Bohr // energies - var getScaledRadius = function( index ) { - var radius = 0; + const getScaledRadius = function( index ) { + let radius = 0; // sum the Bohr energies up to this index - for ( var i = 1; i <= index; i++ ) { - var bohrEnergy = IONIZATION_ENERGY / ( i * i ); + for ( let i = 1; i <= index; i++ ) { + const bohrEnergy = IONIZATION_ENERGY / ( i * i ); radius += bohrEnergy; // radius will be scaled by this sum } return radius * RADIUS_SCALE; }; // draw the radii - for ( var i = ENERGY_LEVELS; i > 0 ; i-- ) { - var scaledRadius = getScaledRadius( i ); - var radius = new Circle( scaledRadius, { stroke: 'grey', lineDash: [ 5, 5 ], center: nucleusCircle.center } ); + for ( let i = ENERGY_LEVELS; i > 0 ; i-- ) { + const scaledRadius = getScaledRadius( i ); + const radius = new Circle( scaledRadius, { stroke: 'grey', lineDash: [ 5, 5 ], center: nucleusCircle.center } ); self.addChild( radius ); } // draw the bounds of each nucleus if ( RSQueryParameters.showDebugShapes ) { - var boundsRectangle = new Path( modelViewTransform.modelToViewShape( atom.boundingRect ), { stroke: 'red' } ); + const boundsRectangle = new Path( modelViewTransform.modelToViewShape( atom.boundingRect ), { stroke: 'red' } ); self.addChild( boundsRectangle ); - var boundingCircle = new Path( modelViewTransform.modelToViewShape( atom.boundingCircle ), { stroke: 'red' } ); + const boundingCircle = new Path( modelViewTransform.modelToViewShape( atom.boundingCircle ), { stroke: 'red' } ); self.addChild( boundingCircle ); } } ); diff --git a/js/rutherfordatom/view/AtomParticleLegendPanel.js b/js/rutherfordatom/view/AtomParticleLegendPanel.js index 4848da4..f68b386 100644 --- a/js/rutherfordatom/view/AtomParticleLegendPanel.js +++ b/js/rutherfordatom/view/AtomParticleLegendPanel.js @@ -43,7 +43,7 @@ define( require => { createPanelContent: function( options ) { // add the legend particle entries - var content = []; + const content = []; content.push( ParticleLegendPanel.createParticleBox( ParticleNodeFactory.createNucleus(), nucleusString ) ); content.push( ParticleLegendPanel.createParticleBox( ParticleNodeFactory.createEnergyLevel(), electronEnergyLevelString ) ); content.push( ParticleLegendPanel.createParticleBox( ParticleNodeFactory.createParticleTrace(), alphaParticleTraceString ) ); diff --git a/js/rutherfordatom/view/AtomPropertiesPanel.js b/js/rutherfordatom/view/AtomPropertiesPanel.js index 0044e5c..57021e3 100644 --- a/js/rutherfordatom/view/AtomPropertiesPanel.js +++ b/js/rutherfordatom/view/AtomPropertiesPanel.js @@ -30,21 +30,21 @@ define( require => { const numberOfProtonsString = require( 'string!RUTHERFORD_SCATTERING/numberOfProtons' ); // a11y strings - var atomSettingsString = RSA11yStrings.atomSettings.value; - var protonsValuePatternString = RSA11yStrings.protonsValuePattern.value; - var protonSliderDescriptionString = RSA11yStrings.protonSliderDescription.value; - var neutronsValuePatternString = RSA11yStrings.neutronsValuePattern.value; - var neutronSliderDescriptionString = RSA11yStrings.neutronSliderDescription.value; + const atomSettingsString = RSA11yStrings.atomSettings.value; + const protonsValuePatternString = RSA11yStrings.protonsValuePattern.value; + const protonSliderDescriptionString = RSA11yStrings.protonSliderDescription.value; + const neutronsValuePatternString = RSA11yStrings.neutronsValuePattern.value; + const neutronSliderDescriptionString = RSA11yStrings.neutronSliderDescription.value; // global, tracking where fingers are for multitouch support // must persist beyond lifetime of the panel so that fingers are tracked when new // panels are created for scene or color profile changes - var FINGER_TRACKER = {}; + const FINGER_TRACKER = {}; // specific interaction properties for the rutherford atom portion, for multitouch // Not specific to an instance of an AtomPropertiesPanel, values of the interaction state Properties should // persist beyond when scene or color profile changes - var interactionPropertyGroup = { + const interactionPropertyGroup = { leftProtonButtonInteractionProperty: new Property( false ), rightProtonButtonInteractionProperty: new Property( false ), protonSliderInteractionProperty: new Property( false ), @@ -63,14 +63,14 @@ define( require => { function AtomPropertiesPanel( content, options ) { // Add the title of the panel content - var atomPropertiesText = new Text( atomString, { + const atomPropertiesText = new Text( atomString, { font: RSConstants.PANEL_TITLE_FONT, fontWeight: 'bold', fill: RSColorProfile.panelTitleColorProperty, maxWidth: 225 } ); - var panelBox = new VBox( { + const panelBox = new VBox( { children: [ atomPropertiesText, content ], align: 'left', spacing: RSConstants.PANEL_CHILD_SPACING @@ -162,23 +162,23 @@ define( require => { this.protonCountProperty = model.protonCountProperty; // each element must have a unique interaction property to support multitouch, see #104 - var leftProtonButtonInteractionProperty = interactionPropertyGroup.leftProtonButtonInteractionProperty; - var rightProtonButtonInteractionProperty = interactionPropertyGroup.rightProtonButtonInteractionProperty; - var leftNeutronButtonInteractionProperty = interactionPropertyGroup.leftNeutronButtonInteractionProperty; - var rightNeutronButtonInteractionProperty = interactionPropertyGroup.leftProtonButtonInteractionProperty; - var protonSliderInteractionProperty = interactionPropertyGroup.protonSliderInteractionProperty; - var neutronSliderInteractionProperty = interactionPropertyGroup.neutronSliderInteractionProperty; + const leftProtonButtonInteractionProperty = interactionPropertyGroup.leftProtonButtonInteractionProperty; + const rightProtonButtonInteractionProperty = interactionPropertyGroup.rightProtonButtonInteractionProperty; + const leftNeutronButtonInteractionProperty = interactionPropertyGroup.leftNeutronButtonInteractionProperty; + const rightNeutronButtonInteractionProperty = interactionPropertyGroup.leftProtonButtonInteractionProperty; + const protonSliderInteractionProperty = interactionPropertyGroup.protonSliderInteractionProperty; + const neutronSliderInteractionProperty = interactionPropertyGroup.neutronSliderInteractionProperty; // these properties are true when any of the dependencies are true - var protonPanelInteractionProperty = DerivedProperty.or( [ leftProtonButtonInteractionProperty, rightProtonButtonInteractionProperty, protonSliderInteractionProperty ] ); - var neutronPanelInteractionProperty = DerivedProperty.or( [ leftNeutronButtonInteractionProperty, rightNeutronButtonInteractionProperty, neutronSliderInteractionProperty ] ); + const protonPanelInteractionProperty = DerivedProperty.or( [ leftProtonButtonInteractionProperty, rightProtonButtonInteractionProperty, protonSliderInteractionProperty ] ); + const neutronPanelInteractionProperty = DerivedProperty.or( [ leftNeutronButtonInteractionProperty, rightNeutronButtonInteractionProperty, neutronSliderInteractionProperty ] ); // must be disposed - var self = this; - var protonInteractionListener = function( protonInteraction ) { + const self = this; + const protonInteractionListener = function( protonInteraction ) { self.protonInteractionProperty.set( protonInteraction ); }; - var neutronInteractionListener = function( neutronInteraction ) { + const neutronInteractionListener = function( neutronInteraction ) { self.neutronInteractionProperty.set( neutronInteraction ); }; protonPanelInteractionProperty.link( protonInteractionListener ); @@ -192,7 +192,7 @@ define( require => { * @param {string} sliderID * @param {Property.} interactionProperty */ - var addFinger = function( sliderID, interactionProperty ) { + const addFinger = function( sliderID, interactionProperty ) { interactionProperty.set( true ); if ( !FINGER_TRACKER[ sliderID ] && FINGER_TRACKER[ sliderID ] !== 0 ) { FINGER_TRACKER[ sliderID ] = 1; // first time finger is down on this thumb @@ -210,7 +210,7 @@ define( require => { * @param {Property.} interactionProperty * @param {Property.} countProperty */ - var removeFinger = function( sliderID, interactionProperty, countProperty ) { + const removeFinger = function( sliderID, interactionProperty, countProperty ) { FINGER_TRACKER[ sliderID ]--; assert && assert( FINGER_TRACKER[ sliderID ] >= 0, 'at least 0 fingers must be using the slider' ); countProperty.set( Util.roundSymmetric( countProperty.value ) ); // proper resolution for nucleons @@ -219,8 +219,8 @@ define( require => { } }; - var sliderWidth = options.minWidth * 0.75; - var numberControlOptions = { + const sliderWidth = options.minWidth * 0.75; + const numberControlOptions = { layoutFunction: NumberControl.createLayoutFunction3( { ySpacing: 3, alignTitle: 'left', @@ -252,10 +252,10 @@ define( require => { }; // allowable range for proton values - var protonCountRange = new RangeWithValue( RSConstants.MIN_PROTON_COUNT, RSConstants.MAX_PROTON_COUNT, + const protonCountRange = new RangeWithValue( RSConstants.MIN_PROTON_COUNT, RSConstants.MAX_PROTON_COUNT, RSConstants.DEFAULT_PROTON_COUNT ); - var protonMajorTicks = [ + const protonMajorTicks = [ { value: protonCountRange.min, label: new Text( protonCountRange.min, { @@ -275,11 +275,11 @@ define( require => { ]; // will track whether we are pressing and holding arrow buttons down - var rightProtonButtonDown = false; - var leftProtonButtonDown = false; + let rightProtonButtonDown = false; + let leftProtonButtonDown = false; // Number control for protons - var protonNumberControlOptions = _.extend( {}, numberControlOptions ); + const protonNumberControlOptions = _.extend( {}, numberControlOptions ); protonNumberControlOptions.titleNodeOptions = _.extend( {}, numberControlOptions.titleNodeOptions, { fill: RSColorProfile.protonsLabelColorProperty } ); protonNumberControlOptions.arrowButtonOptions = { @@ -317,7 +317,7 @@ define( require => { descriptionContent: protonSliderDescriptionString, containerTagName: 'div' } ); - var protonNumberControl = new NumberControl( numberOfProtonsString, this.protonCountProperty, protonCountRange, protonNumberControlOptions ); + const protonNumberControl = new NumberControl( numberOfProtonsString, this.protonCountProperty, protonCountRange, protonNumberControlOptions ); function protonCountListener() { @@ -333,10 +333,10 @@ define( require => { this.protonCountProperty.link( protonCountListener ); - var neutronCountRange = new RangeWithValue( RSConstants.MIN_NEUTRON_COUNT, RSConstants.MAX_NEUTRON_COUNT, + const neutronCountRange = new RangeWithValue( RSConstants.MIN_NEUTRON_COUNT, RSConstants.MAX_NEUTRON_COUNT, RSConstants.DEFAULT_NEUTRON_COUNT ); - var neutronMajorTicks = [ { + const neutronMajorTicks = [ { value: neutronCountRange.min, label: new Text( neutronCountRange.min, { font: RSConstants.PANEL_TICK_FONT, @@ -355,11 +355,11 @@ define( require => { ]; // will track whether we are pressing and holding arrow buttons down - var leftNeutronButtonDown = false; - var rightNeutronButtonDown = false; + let leftNeutronButtonDown = false; + let rightNeutronButtonDown = false; // Number control for protons - var neutronNumberControlOptions = _.extend( {}, numberControlOptions ); + const neutronNumberControlOptions = _.extend( {}, numberControlOptions ); neutronNumberControlOptions.titleNodeOptions = _.extend( {}, numberControlOptions.titleNodeOptions, { fill: RSColorProfile.neutronsLabelColorProperty } ); @@ -400,7 +400,7 @@ define( require => { rightNeutronButtonDown = true; } }; - var neutronNumberControl = new NumberControl( numberOfNeutronsString, this.neutronCountProperty, neutronCountRange, neutronNumberControlOptions ); + const neutronNumberControl = new NumberControl( numberOfNeutronsString, this.neutronCountProperty, neutronCountRange, neutronNumberControlOptions ); function neutronCountListener() { diff --git a/js/rutherfordatom/view/AtomSpaceNode.js b/js/rutherfordatom/view/AtomSpaceNode.js index b494c3a..b9889a0 100644 --- a/js/rutherfordatom/view/AtomSpaceNode.js +++ b/js/rutherfordatom/view/AtomSpaceNode.js @@ -20,8 +20,8 @@ define( require => { const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' ); // a11y strings - var observationWindowString = RSA11yStrings.observationWindow.value; - var atomSpaceDescriptionString = RSA11yStrings.atomSpaceDescription.value; + const observationWindowString = RSA11yStrings.observationWindow.value; + const atomSpaceDescriptionString = RSA11yStrings.atomSpaceDescription.value; /** * @param {RSBaseModel} model @@ -49,7 +49,7 @@ define( require => { this.atomsNode = new AtomCollectionNode( model.atomSpace, modelViewTransform ); ParticleSpaceNode.call( this, model.atomSpace, showAlphaTraceProperty, modelViewTransform, options ); - var self = this; + const self = this; if ( RSQueryParameters.showDebugShapes ) { model.atomSpace.particleTransitionedEmitter.addListener( function( particle ) { @@ -77,8 +77,8 @@ define( require => { return; } - var x = this.centerX - this.atomsNode.image.width / 2; - var y = this.centerY - this.atomsNode.image.height / 2; + const x = this.centerX - this.atomsNode.image.width / 2; + const y = this.centerY - this.atomsNode.image.height / 2; context.drawImage( this.atomsNode.image, x, y, this.atomsNode.image.width, this.atomsNode.image.height ); } } ); // inherit diff --git a/js/rutherfordatom/view/NucleusSpaceNode.js b/js/rutherfordatom/view/NucleusSpaceNode.js index 104a41d..e46124c 100644 --- a/js/rutherfordatom/view/NucleusSpaceNode.js +++ b/js/rutherfordatom/view/NucleusSpaceNode.js @@ -17,8 +17,8 @@ define( require => { const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' ); // a11y strings - var observationWindowString = RSA11yStrings.observationWindow.value; - var nucleusSpaceDescriptionString = RSA11yStrings.nucleusSpaceDescription.value; + const observationWindowString = RSA11yStrings.observationWindow.value; + const nucleusSpaceDescriptionString = RSA11yStrings.nucleusSpaceDescription.value; /** * @param {RSBaseModel} model @@ -53,7 +53,7 @@ define( require => { // updated correctly - when marked as 'dirty', the atom node will be explicitly redrawn to ensure that // it looks correct in the space // does not need to be unlinked, space will exist for life of sim - var self = this; + const self = this; model.stepEmitter.addListener( function( dt ) { if ( self.atomNode.isDirty ) { if ( dt ) { @@ -84,8 +84,8 @@ define( require => { return; } - var x = this.centerX - this.atomNode.image.width / 2; - var y = this.centerY - this.atomNode.image.height / 2; + const x = this.centerX - this.atomNode.image.width / 2; + const y = this.centerY - this.atomNode.image.height / 2; context.drawImage( this.atomNode.image, x, y, this.atomNode.image.width, this.atomNode.image.height ); } diff --git a/js/rutherfordatom/view/RutherfordAtomScreenView.js b/js/rutherfordatom/view/RutherfordAtomScreenView.js index 0db5b9d..6bd7105 100644 --- a/js/rutherfordatom/view/RutherfordAtomScreenView.js +++ b/js/rutherfordatom/view/RutherfordAtomScreenView.js @@ -38,10 +38,10 @@ define( require => { const pattern0NuclearScaleString = require( 'string!RUTHERFORD_SCATTERING/pattern.0nuclearScale' ); // a11yStrings - var switchScaleString = RSA11yStrings.switchScale.value; - var switchScaleDescriptionString = RSA11yStrings.switchScaleDescription.value; - var nuclearScaleViewString = RSA11yStrings.nuclearScaleView.value; - var atomicScaleViewString = RSA11yStrings.atomicScaleView.value; + const switchScaleString = RSA11yStrings.switchScale.value; + const switchScaleDescriptionString = RSA11yStrings.switchScaleDescription.value; + const nuclearScaleViewString = RSA11yStrings.nuclearScaleView.value; + const atomicScaleViewString = RSA11yStrings.atomicScaleView.value; // images const atomImage = require( 'image!RUTHERFORD_SCATTERING/Atom.png' ); @@ -53,42 +53,42 @@ define( require => { */ function RutherfordAtomScreenView( model ) { - var nucleusScaleString = StringUtils.format( pattern0NuclearScaleString, '1.5 x 10-13' ); - var atomicScaleString = StringUtils.format( pattern0AtomicScaleString, '6.0 x 10-10' ); + const nucleusScaleString = StringUtils.format( pattern0NuclearScaleString, '1.5 x 10-13' ); + const atomicScaleString = StringUtils.format( pattern0AtomicScaleString, '6.0 x 10-10' ); RSBaseScreenView.call( this, model, nucleusScaleString, createSpaceNode, { includeElectronLegend: false } ); // scale info for the 'atom' scene, only visible when atom scene is selected - var atomicScaleInfoNode = new ScaleInfoNode( atomicScaleString, this.spaceNode.getWidth(), { + const atomicScaleInfoNode = new ScaleInfoNode( atomicScaleString, this.spaceNode.getWidth(), { center: this.scaleInfoNode.center } ); this.addChild( atomicScaleInfoNode ); // create the panels of the control panel on the right - var createPanels = function() { + const createPanels = function() { - var legendContent; - var atomSceneVisible = model.sceneProperty.value === 'atom'; + let legendContent; + const atomSceneVisible = model.sceneProperty.value === 'atom'; // create content for the control panels - var atomLegendContent = AtomParticleLegendPanel.createPanelContent( { resize: false } ); - var nuclearLegendContent = NuclearParticleLegendPanel.createPanelContent( { + const atomLegendContent = AtomParticleLegendPanel.createPanelContent( { resize: false } ); + const nuclearLegendContent = NuclearParticleLegendPanel.createPanelContent( { resize: false, includeElectron: false, includePlumPudding: false } ); - var particlePropertiesContent = AlphaParticlePropertiesPanel.createPanelContent( model.energyInteractionProperty, model.alphaParticleEnergyProperty, self.showAlphaTraceProperty, { resize: false } ); - var atomPropertiesContent = AtomPropertiesPanel.createPanelContent( model, { resize: false } ); + const particlePropertiesContent = AlphaParticlePropertiesPanel.createPanelContent( model.energyInteractionProperty, model.alphaParticleEnergyProperty, self.showAlphaTraceProperty, { resize: false } ); + const atomPropertiesContent = AtomPropertiesPanel.createPanelContent( model, { resize: false } ); // make sure that content for all panels are aligned and the legend content is aligned to the left // this content does not include title - var contentAlignGroup = new AlignGroup( { matchVertical: false } ); - var atomContentBox = contentAlignGroup.createBox( atomLegendContent, { xAlign: ParticleLegendPanel.LEGEND_CONTENT_ALIGN } ); - var nuclearContentBox = contentAlignGroup.createBox( nuclearLegendContent, { xAlign: ParticleLegendPanel.LEGEND_CONTENT_ALIGN } ); - var particlePropertiesContentBox = contentAlignGroup.createBox( particlePropertiesContent ); - var atromPropertiesContentBox = contentAlignGroup.createBox( atomPropertiesContent ); + const contentAlignGroup = new AlignGroup( { matchVertical: false } ); + const atomContentBox = contentAlignGroup.createBox( atomLegendContent, { xAlign: ParticleLegendPanel.LEGEND_CONTENT_ALIGN } ); + const nuclearContentBox = contentAlignGroup.createBox( nuclearLegendContent, { xAlign: ParticleLegendPanel.LEGEND_CONTENT_ALIGN } ); + const particlePropertiesContentBox = contentAlignGroup.createBox( particlePropertiesContent ); + const atromPropertiesContentBox = contentAlignGroup.createBox( atomPropertiesContent ); // create content for the legend panels if ( atomSceneVisible ) { @@ -99,10 +99,10 @@ define( require => { } // create the panels - var panelOptions = { resize: false }; - var legendPanel = atomSceneVisible ? new AtomParticleLegendPanel( legendContent, panelOptions ) : new NuclearParticleLegendPanel( legendContent, panelOptions ); - var particlePropertiesPanel = new AlphaParticlePropertiesPanel( particlePropertiesContentBox, panelOptions ); - var atomPropertiesPanel = new AtomPropertiesPanel( atromPropertiesContentBox, panelOptions ); + const panelOptions = { resize: false }; + const legendPanel = atomSceneVisible ? new AtomParticleLegendPanel( legendContent, panelOptions ) : new NuclearParticleLegendPanel( legendContent, panelOptions ); + const particlePropertiesPanel = new AlphaParticlePropertiesPanel( particlePropertiesContentBox, panelOptions ); + const atomPropertiesPanel = new AtomPropertiesPanel( atromPropertiesContentBox, panelOptions ); return [ legendPanel, @@ -113,7 +113,7 @@ define( require => { // when various panels are added/removed due to changing color profile or scene, reset the accessible order var self = this; - var restoreAccessibleOrder = function() { + const restoreAccessibleOrder = function() { self.playAreaNode.accessibleOrder = [ self.gunNode ]; @@ -130,8 +130,8 @@ define( require => { // should be updated, and the control/legend panels need to change // no need to unlink, screen view exists for life of sim model.sceneProperty.link( function( scene ) { - var beam = self.beamNode; - var atomSceneVisible = scene === 'atom'; + const beam = self.beamNode; + const atomSceneVisible = scene === 'atom'; // update visibility of scene specific scale info self.scaleInfoNode.visible = !atomSceneVisible; @@ -148,7 +148,7 @@ define( require => { } // create the new control panel - var panels = createPanels(); + const panels = createPanels(); controlPanel = self.createControlPanel( panels ); self.addChild( controlPanel ); @@ -157,8 +157,8 @@ define( require => { // create radio buttons for the scene - new buttons must be created // every time the color profile changes - var nucleusIcon = RutherfordNucleusNode.RutherfordNucleusIcon( 20, 20 ); - var buttonOptions = { scale: 0.18 }; + const nucleusIcon = RutherfordNucleusNode.RutherfordNucleusIcon( 20, 20 ); + const buttonOptions = { scale: 0.18 }; /** * Create the RadioButonGroup that will act as the scene selection control in this sim. @@ -166,7 +166,7 @@ define( require => { * @param {Image} atomIconImage - the icon for the atomic scene, changes with color profile * @returns {RadioButtonGroup} - returns a RadioButtonGroup that must be disposed when profile changes */ - var createRadioButtons = function( atomIconImage ) { + const createRadioButtons = function( atomIconImage ) { return new RadioButtonGroup( model.sceneProperty, [ { value: 'atom', node: new Image( atomIconImage, buttonOptions ), labelContent: atomicScaleViewString }, { value: 'nucleus', node: nucleusIcon, labelContent: nuclearScaleViewString } @@ -204,10 +204,10 @@ define( require => { self.sceneRadioButtonGroup.dispose(); // get the correct image for the 'atom' scene icon - var iconImage = ( profileName === ColorProfile.PROJECTOR_COLOR_PROFILE_NAME ) ? atomProjectorImage : atomImage; + const iconImage = ( profileName === ColorProfile.PROJECTOR_COLOR_PROFILE_NAME ) ? atomProjectorImage : atomImage; // create the new radio button group - var newButtonGroup = createRadioButtons( iconImage ); + const newButtonGroup = createRadioButtons( iconImage ); self.sceneRadioButtonGroup = newButtonGroup; self.controlAreaNode.addChild( newButtonGroup ); @@ -235,26 +235,26 @@ define( require => { var createSpaceNode = function( model, showAlphaTraceProperty, modelViewTransform, canvasBounds ) { // create the single nucleus representation scene - var nucleusSpaceNode = new NucleusSpaceNode( model, showAlphaTraceProperty, modelViewTransform, { + const nucleusSpaceNode = new NucleusSpaceNode( model, showAlphaTraceProperty, modelViewTransform, { canvasBounds: canvasBounds } ); // create the multiple atom representation scene - var atomSpaceNode = new AtomSpaceNode( model, showAlphaTraceProperty, modelViewTransform, { + const atomSpaceNode = new AtomSpaceNode( model, showAlphaTraceProperty, modelViewTransform, { canvasBounds: canvasBounds } ); if ( RSQueryParameters.showErrorCount ) { // show the number of particles that were removed from the space in error - var errorCountPattern = 'Error count: {{numRemoved}}'; - var errorText = new Text( '', { + const errorCountPattern = 'Error count: {{numRemoved}}'; + const errorText = new Text( '', { font: new PhetFont( 18 ), fill: 'red', leftBottom: atomSpaceNode.leftTop } ); atomSpaceNode.addChild( errorText ); - var atomsRemoved = 0; + let atomsRemoved = 0; model.atomSpace.particleRemovedFromAtomEmitter.addListener( function( particle ) { atomsRemoved += 1; errorText.text = StringUtils.fillIn( errorCountPattern, { @@ -272,7 +272,7 @@ define( require => { // update which scene is visible and remove all particles // no need to unlink, screen view exists for life of sim model.sceneProperty.link( function( scene ) { - var nucleusVisible = scene === 'nucleus'; + const nucleusVisible = scene === 'nucleus'; // set visibility of model space model.nucleusSpace.isVisible = nucleusVisible; diff --git a/js/rutherfordatom/view/RutherfordNucleusNode.js b/js/rutherfordatom/view/RutherfordNucleusNode.js index e03a960..4f5d723 100644 --- a/js/rutherfordatom/view/RutherfordNucleusNode.js +++ b/js/rutherfordatom/view/RutherfordNucleusNode.js @@ -20,12 +20,12 @@ define( require => { const rutherfordScattering = require( 'RUTHERFORD_SCATTERING/rutherfordScattering' ); // constants - var MIN_NUCLEUS_RADIUS = 20; // view coordinates - var OUTLINE_LINE_WIDTH = 1.5; - var OUTLINE_LINE_DASH = [ 2, 3 ]; - var MIN_PARTICLE_COUNT = RSConstants.MIN_PROTON_COUNT + RSConstants.MIN_NEUTRON_COUNT; - var MAX_PARTICLE_COUNT = RSConstants.MAX_PROTON_COUNT + RSConstants.MAX_NEUTRON_COUNT; - var PARTICLE_COUNT_EXP = 0.333; + const MIN_NUCLEUS_RADIUS = 20; // view coordinates + const OUTLINE_LINE_WIDTH = 1.5; + const OUTLINE_LINE_DASH = [ 2, 3 ]; + const MIN_PARTICLE_COUNT = RSConstants.MIN_PROTON_COUNT + RSConstants.MIN_NEUTRON_COUNT; + const MAX_PARTICLE_COUNT = RSConstants.MAX_PROTON_COUNT + RSConstants.MAX_NEUTRON_COUNT; + const PARTICLE_COUNT_EXP = 0.333; /** * The Rutherford atom is build by randomly drawing proton & neutron images to a CanvasNode. This canvas is then @@ -40,7 +40,7 @@ define( require => { function RutherfordNucleusNode( userInteractionProperty, protonCountProperty, neutronCountProperty, rutherfordNucleus, options ) { // max radius of an atom with MAX protons & neutrons - var maxRadius = MIN_NUCLEUS_RADIUS / Math.pow( MIN_PARTICLE_COUNT, PARTICLE_COUNT_EXP ) * + const maxRadius = MIN_NUCLEUS_RADIUS / Math.pow( MIN_PARTICLE_COUNT, PARTICLE_COUNT_EXP ) * Math.pow( MAX_PARTICLE_COUNT, PARTICLE_COUNT_EXP ); // set canvasBounds based on max radius of atom @@ -49,7 +49,7 @@ define( require => { CanvasNode.call( this, options ); - var self = this; + const self = this; // @private this.userInteractionProperty = userInteractionProperty; @@ -83,7 +83,7 @@ define( require => { this.timeSinceDirty = 0; // ms // generate proton image - asynchronous - var protonNode = ParticleNodeFactory.createProton(); + const protonNode = ParticleNodeFactory.createProton(); protonNode.toImage( function( image, x, y ) { self.protonImage = image; self.updateAtomImage(); @@ -91,7 +91,7 @@ define( require => { } ); // generate neutron image - asynchronous - var neutronNode = ParticleNodeFactory.createNeutron(); + const neutronNode = ParticleNodeFactory.createNeutron(); neutronNode.toImage( function( image, x, y ) { self.neutronImage = image; self.updateAtomImage(); @@ -99,7 +99,7 @@ define( require => { } ); // update atom image when proton count changes - var protonCountListener = function( propertyValue ) { + const protonCountListener = function( propertyValue ) { self.numberOfProtons = propertyValue; self.renderAtomOutline = self.userInteractionProperty.value; // Only render the outline when interacting self.updateAtomImage(); @@ -108,7 +108,7 @@ define( require => { protonCountProperty.link( protonCountListener ); // update atom image when neutron count changes - var neutronCountListener = function( propertyValue ) { + const neutronCountListener = function( propertyValue ) { self.numberOfNeutrons = propertyValue; self.renderAtomOutline = self.userInteractionProperty.value; // Only render the outline when interacting self.updateAtomImage(); @@ -117,7 +117,7 @@ define( require => { neutronCountProperty.link( neutronCountListener ); // update atom image when user interaction stops - var userInteractionListener = function( userInteraction ) { + const userInteractionListener = function( userInteraction ) { if ( self.renderAtomOutline ) { self.renderAtomOutline = false; self.updateAtomImage(); @@ -154,15 +154,15 @@ define( require => { updateAtomImage: function() { // Calculate the radius of the nucleus - var currentParticles = this.numberOfProtons + this.numberOfNeutrons; - var C = MIN_NUCLEUS_RADIUS / Math.pow( MIN_PARTICLE_COUNT, PARTICLE_COUNT_EXP ); + const currentParticles = this.numberOfProtons + this.numberOfNeutrons; + const C = MIN_NUCLEUS_RADIUS / Math.pow( MIN_PARTICLE_COUNT, PARTICLE_COUNT_EXP ); this.radius = C * Math.pow( currentParticles, PARTICLE_COUNT_EXP ); assert && assert( this.radius > 0, 'Rutherford atom radius <= 0' ); this.invalidatePaint(); // generate atom image - asynchronous - var self = this; + const self = this; this.toImage( function( image, x, y ) { // @public (read-only) self.image = image; @@ -177,7 +177,7 @@ define( require => { */ paintCanvas: function( context ) { - var bounds = this.canvasBounds; + const bounds = this.canvasBounds; // clear context.clearRect( bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight() ); @@ -199,7 +199,7 @@ define( require => { return; } - var boundPaintNucleus = paintNucleusIcon.bind( this, this.rutherfordNucleus, bounds, context, 'canvasImage' ); + const boundPaintNucleus = paintNucleusIcon.bind( this, this.rutherfordNucleus, bounds, context, 'canvasImage' ); boundPaintNucleus(); // notify as dirty so that the nucleus gets redrawn @@ -219,9 +219,9 @@ define( require => { RutherfordNucleusIcon: function( protonCount, neutronCount ) { // create static properties and nucleus for the icon - var protonCountProperty = new Property( protonCount ); - var neutronCountProperty = new Property( neutronCount ); - var nucleus = new RutherfordNucleus( protonCountProperty, neutronCountProperty ); + const protonCountProperty = new Property( protonCount ); + const neutronCountProperty = new Property( neutronCount ); + const nucleus = new RutherfordNucleus( protonCountProperty, neutronCountProperty ); return new IconCanvasNode( nucleus ); } @@ -242,8 +242,8 @@ define( require => { this.nucleus = nucleus; // max radius of an atom with MAX protons & neutrons - var numberOfParticles = nucleus.protonCountProperty.get() + nucleus.neutronCountProperty.get(); - var maxRadius = MIN_NUCLEUS_RADIUS / Math.pow( MIN_PARTICLE_COUNT, PARTICLE_COUNT_EXP ) * + const numberOfParticles = nucleus.protonCountProperty.get() + nucleus.neutronCountProperty.get(); + const maxRadius = MIN_NUCLEUS_RADIUS / Math.pow( MIN_PARTICLE_COUNT, PARTICLE_COUNT_EXP ) * Math.pow( numberOfParticles, PARTICLE_COUNT_EXP ); // @private - used to center elements drawn in the context @@ -283,12 +283,12 @@ define( require => { * @param {string} render - 'canvasArc' | 'canvasImage', determines rendering method, see above */ var paintNucleusIcon = function( nucleus, nucleusBounds, context, render ) { - var protons = nucleus.protons.getArray().slice( 0 ); - var neutrons = nucleus.neutrons.getArray().slice( 0 ); - var nucleons = protons.concat( neutrons ); + const protons = nucleus.protons.getArray().slice( 0 ); + const neutrons = nucleus.neutrons.getArray().slice( 0 ); + const nucleons = protons.concat( neutrons ); // get the number of layers in the particle - var zLayer = 0; + let zLayer = 0; nucleons.forEach( function( nucleon ) { if ( nucleon.zLayerProperty.get() > zLayer ) { zLayer = nucleon.zLayerProperty.get(); @@ -296,12 +296,12 @@ define( require => { } ); // add the layers, starting from the largest which is in the back - var self = this; + const self = this; for ( var i = zLayer; i >= 0; i-- ) { nucleons.forEach( function( nucleon ) { if ( nucleon.zLayerProperty.get() === i ) { - var xN = nucleon.positionProperty.get().x; - var yN = nucleon.positionProperty.get().y; + let xN = nucleon.positionProperty.get().x; + let yN = nucleon.positionProperty.get().y; if ( render === 'canvasArc' ) { // drawing with arcs is a little slower, but the result is less pixilated, so