Skip to content

Commit

Permalink
always show outline of photons when split, see #65
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Dec 10, 2024
1 parent 10a29f0 commit 735ccc6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
Binary file added images/greenPhotonOutline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions images/greenPhotonOutline_png.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
/* @formatter:off */

import asyncLoader from '../../phet-core/js/asyncLoader.js';

const image = new Image();
const unlock = asyncLoader.createLock( image );
image.onload = unlock;
image.src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADQAAAAzCAYAAADYfStTAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAfZSURBVGhD1Zp5bBzVHcd3Zu9z9nJ87a7t9XodGyfCCdhtFJscdQ5CDiAJIHrQkrqq1BJUNVBoRRGlpQ3/FFEOIRHSVmqpojppQk4IdmKT004CMXZ8ra+1vRvvnT1mz+n7jZ4Nm9jxgbF3P5L1m/n93lrznTfz3vv93hAMw3DmEoZJcD200+wJOYvCMVoVjNzKijExEZfgRqQCxbCQJ/IoROoeSqTq4ZH8EP7ZnDEngkYDI+W9zhtbrd7e1Xa/tTKeiAlxaFIIhpPQyrI/z6byzxqUhR/rKeMnXJIXxuFZM2tBsURU/KWtubbN1rLLGbpZht0sCqGqWy3J6BDzpaMSgcyGLpSOJ+JC1FvZwVhQ6wu5Cj0hl4nhxPn4JxwBKfAZtaUHl2ZXvrVIlnsZu2fMjAUlmDj/2vD5Z68OfbYnFA1kgA8u3KQtPWBQmk/kUvlnBFyhj218F+CG2G8NVQz7+qp7XO3bHP6RZTjEyZTpzn8nb+3v9ajnsGvazEjQkLfvgYbuw++6acdiOM+S6y8s11X9OU9VdIwkuFG20Szx0W5jq+3y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9 changes: 9 additions & 0 deletions images/license.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,14 @@
"projectURL": "https://phet.colorado.edu",
"license": "contact [email protected]",
"notes": "created by John Blanco"
},
"greenPhotonOutline.png": {
"text": [
"Copyright 2023 University of Colorado Boulder"
],
"projectURL": "https://phet.colorado.edu",
"license": "contact [email protected]",
"notes": "created by John Blanco"
}

}
2 changes: 1 addition & 1 deletion js/photons/model/PhotonsExperimentSceneModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class PhotonsExperimentSceneModel {

const mirrorDistanceProportion = 0.5;
const horizontalDetectorXPosition = mirrorDistanceProportion * PATH_LENGTH_UNIT;
const horizontalDetectorYPosition = ( 1 - mirrorDistanceProportion ) * PATH_LENGTH_UNIT;
const horizontalDetectorYPosition = ( 1 - mirrorDistanceProportion ) * PATH_LENGTH_UNIT * 1.5;
this.horizontalPolarizationDetector = new PhotonDetector( new Vector2( horizontalDetectorXPosition, -horizontalDetectorYPosition ), 'down', {
displayMode: this.laser.emissionMode === 'singlePhoton' ? 'count' : 'rate',
tandem: providedOptions.tandem.createTandem( 'horizontalPolarizationDetector' )
Expand Down
57 changes: 42 additions & 15 deletions js/photons/view/PhotonSprites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Vector2 from '../../../../dot/js/Vector2.js';
import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js';
import { Sprite, SpriteImage, SpriteInstance, SpriteInstanceTransformType, Sprites } from '../../../../scenery/js/imports.js';
import greenPhoton_png from '../../../images/greenPhoton_png.js';
import greenPhotonOutline_png from '../../../images/greenPhotonOutline_png.js';
import quantumMeasurement from '../../quantumMeasurement.js';
import Photon from '../model/Photon.js';

Expand All @@ -33,23 +34,30 @@ export default class PhotonSprites extends Sprites {
// The scale value used to render the photons.
private readonly photonScale: number;

// The sprite used to render the photons
// The sprites used to render the photons.
private readonly photonSprite: Sprite;
private readonly photonOutlineSprite: Sprite;

public constructor( photons: Photon[], modelViewTransform: ModelViewTransform2, canvasBounds: Bounds2 ) {

// Create the sprite that will be used to represent the photons.
// Create the sprites that will be used to represent the photons.
const photonSprite = new Sprite( new SpriteImage(
greenPhoton_png,
new Vector2( greenPhoton_png.width / 2, greenPhoton_png.height / 2 ),
{ pickable: false }
) );

// array of sprite instances, there will be one for each photon that is rendered
const photonOutlineSprite = new Sprite( new SpriteImage(
greenPhotonOutline_png,
new Vector2( greenPhotonOutline_png.width / 2, greenPhotonOutline_png.height / 2 ),
{ pickable: false }
) );

// array of sprite instances, there will be two for each photon that is rendered
const spriteInstances: SpriteInstance[] = [];

super( {
sprites: [ photonSprite ],
sprites: [ photonSprite, photonOutlineSprite ],
spriteInstances: spriteInstances,
renderer: 'webgl',
pickable: false,
Expand All @@ -68,6 +76,7 @@ export default class PhotonSprites extends Sprites {
this.photons = photons;
this.modelViewTransform = modelViewTransform;
this.photonSprite = photonSprite;
this.photonOutlineSprite = photonOutlineSprite;
}

/**
Expand All @@ -81,38 +90,56 @@ export default class PhotonSprites extends Sprites {

const photon = this.photons[ i ];

// Iterate over the two possible photon states
// Iterate over the photon motion states.
for ( const photonMotionState of photon.possibleMotionStates ) {

if ( photonMotionState.probability > 0 ) {
numberOfPhotonsDisplayed++;
const photonStatePosition = photonMotionState.position;

// Add a new sprite instance to our list if we don't have enough.
if ( numberOfPhotonsDisplayed > this.spriteInstances.length ) {
const newSpriteInstance = SpriteInstance.pool.fetch();
newSpriteInstance.transformType = SpriteInstanceTransformType.AFFINE;
this.spriteInstances.push( newSpriteInstance );
// Add new sprite instances to our list if we don't have enough.
if ( numberOfPhotonsDisplayed * 2 > this.spriteInstances.length ) {

const newInteriorSpriteInstance = SpriteInstance.pool.fetch();
newInteriorSpriteInstance.transformType = SpriteInstanceTransformType.AFFINE;
this.spriteInstances.push( newInteriorSpriteInstance );

const newOutlineSpriteInstance = SpriteInstance.pool.fetch();
newOutlineSpriteInstance.transformType = SpriteInstanceTransformType.AFFINE;
this.spriteInstances.push( newOutlineSpriteInstance );
}

// Update the matrix that controls where this photon is rendered.
const spriteInstance = this.spriteInstances[ numberOfPhotonsDisplayed - 1 ];
spriteInstance.sprite = this.photonSprite;
spriteInstance.matrix.setToAffine(
const interiorSpriteInstance = this.spriteInstances[ ( numberOfPhotonsDisplayed - 1 ) * 2 ];
interiorSpriteInstance.sprite = this.photonSprite;
interiorSpriteInstance.matrix.setToAffine(
this.photonScale,
0,
this.modelViewTransform.modelToViewX( photonStatePosition.x ),
0,
this.photonScale,
this.modelViewTransform.modelToViewY( photonStatePosition.y )
);
interiorSpriteInstance.alpha = photonMotionState.probability; // Probability based opacity
// interiorSpriteInstance.alpha = Math.pow( photonMotionState.probability, 1.25 ); // Probability based opacity

const outlineSpriteInstance = this.spriteInstances[ ( numberOfPhotonsDisplayed - 1 ) * 2 + 1 ];
outlineSpriteInstance.sprite = this.photonOutlineSprite;
outlineSpriteInstance.matrix.setToAffine(
this.photonScale,
0,
this.modelViewTransform.modelToViewX( photonStatePosition.x ),
0,
this.photonScale,
this.modelViewTransform.modelToViewY( photonStatePosition.y )
);
spriteInstance.alpha = photonMotionState.probability; // Probability based opacity
outlineSpriteInstance.alpha = 1;
}
}
}

// Free up any unused sprite instances.
while ( this.spriteInstances.length > numberOfPhotonsDisplayed ) {
while ( this.spriteInstances.length > numberOfPhotonsDisplayed * 2 ) {
const unusedSpriteInstance = this.spriteInstances.pop();
unusedSpriteInstance && unusedSpriteInstance.freeToPool();
}
Expand Down

0 comments on commit 735ccc6

Please sign in to comment.