Skip to content

Commit

Permalink
Added ApertureType, see #198
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Nov 28, 2018
1 parent 3a03638 commit 478378a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
16 changes: 16 additions & 0 deletions js/diffraction/model/ApertureType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2018, University of Colorado Boulder

/**
* Determines the selected aperture shape.
*
* @author Sam Reid (PhET Interactive Simulations)
*/
define( require => {
'use strict';

// modules
const Enumeration = require( 'PHET_CORE/Enumeration' );
const waveInterference = require( 'WAVE_INTERFERENCE/waveInterference' );

return waveInterference.register( 'ApertureType', new Enumeration( [ 'CIRCLE', 'RECTANGLE', 'SLITS' ] ) );
} );
3 changes: 2 additions & 1 deletion js/diffraction/model/DiffractionModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define( require => {
'use strict';

// modules
const ApertureType = require( 'WAVE_INTERFERENCE/diffraction/model/ApertureType' );
const BooleanProperty = require( 'AXON/BooleanProperty' );
const NumberProperty = require( 'AXON/NumberProperty' );
const Property = require( 'AXON/Property' );
Expand All @@ -34,7 +35,7 @@ define( require => {
this.angleProperty = new NumberProperty( 0 );

// @public {Property.<string>} selected scene
this.sceneProperty = new Property( 'circle' ); // TODO: enum
this.sceneProperty = new Property( ApertureType.CIRCLE ); // TODO: enum
}

/**
Expand Down
17 changes: 9 additions & 8 deletions js/diffraction/view/DiffractionScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define( require => {
'use strict';

// modules
const ApertureType = require( 'WAVE_INTERFERENCE/diffraction/model/ApertureType' );
const Circle = require( 'SCENERY/nodes/Circle' );
const Dimension2 = require( 'DOT/Dimension2' );
const Image = require( 'SCENERY/nodes/Image' );
Expand Down Expand Up @@ -69,10 +70,10 @@ define( require => {
this.addChild( resetAllButton );

const toggleButtonsContent = [ {
value: 'rectangle',
value: ApertureType.RECTANGLE,
node: new Rectangle( 0, 0, 20, 20, { fill: 'black' } )
}, {
value: 'circle',
value: ApertureType.CIRCLE,
node: new Circle( 10, { fill: 'black' } )
} ];

Expand Down Expand Up @@ -169,9 +170,9 @@ define( require => {
this.addChild( this.slitsControlPanel );

model.sceneProperty.link( scene => {
this.squareControlPanel.visible = scene === 'rectangle';
this.gaussianControlPanel.visible = scene === 'circle';
this.slitsControlPanel.visible = scene === 'slits';
this.squareControlPanel.visible = scene === ApertureType.RECTANGLE;
this.gaussianControlPanel.visible = scene === ApertureType.CIRCLE;
this.slitsControlPanel.visible = scene === ApertureType.SLITS;
} );

const beamWidth = 40;
Expand Down Expand Up @@ -266,15 +267,15 @@ define( require => {

let i;

if ( this.model.sceneProperty.value === 'rectangle' ) {
if ( this.model.sceneProperty.value === ApertureType.RECTANGLE ) {
const rectWidth = this.model.squareWidthProperty.value;
const rectHeight = this.model.squareHeightProperty.value;
syntheticApertureContext.fillRect( width / 2 - rectWidth / 2, width / 2 - rectHeight / 2,
rectWidth, rectHeight );
displayedApertureContext.fillRect( width / 2 - rectWidth / 2, width / 2 - rectHeight / 2,
rectWidth, rectHeight );
}
else if ( this.model.sceneProperty.value === 'circle' ) {
else if ( this.model.sceneProperty.value === ApertureType.CIRCLE ) {
for ( i = 0; i < width; i++ ) {
for ( let k = 0; k < height; k++ ) {
const v = Util.clamp( Math.floor( gaussian(
Expand All @@ -290,7 +291,7 @@ define( require => {
}
}
}
else if ( this.model.sceneProperty.value === 'slits' ) {
else if ( this.model.sceneProperty.value === ApertureType.SLITS ) {

syntheticApertureContext.rotate( this.model.angleProperty.value );
displayedApertureContext.rotate( this.model.angleProperty.value );
Expand Down

0 comments on commit 478378a

Please sign in to comment.