From 735ccc6c880ee512c8cf32bbaf5f84202e556428 Mon Sep 17 00:00:00 2001 From: jbphet Date: Tue, 10 Dec 2024 15:15:22 -0700 Subject: [PATCH] always show outline of photons when split, see https://github.com/phetsims/quantum-measurement/issues/65 --- images/greenPhotonOutline.png | Bin 0 -> 2116 bytes images/greenPhotonOutline_png.ts | 10 +++ images/license.json | 9 +++ .../model/PhotonsExperimentSceneModel.ts | 2 +- js/photons/view/PhotonSprites.ts | 57 +++++++++++++----- 5 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 images/greenPhotonOutline.png create mode 100644 images/greenPhotonOutline_png.ts diff --git a/images/greenPhotonOutline.png b/images/greenPhotonOutline.png new file mode 100644 index 0000000000000000000000000000000000000000..1fddbd2891f800fe1680e89e3742186191bfab55 GIT binary patch literal 2116 zcmV-K2)p-*P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D2iZwPK~!i%)tY&1 z9Mv7icV_Q%_HumfuI=@D9UCXY3D|8En;dlxLJlAaAbQY}x~kL?R5eg&MG>W?4gVBT z4j~cJR%)rDI%z^q2zFwV(@p|0c6_a`wY?kfojqpH>HCeI4V&2Ufw6Z#lJ%SU{oY#h zoj3E|`~BV!48w5d5{5}|J+#y82|0_xF<(ZEDE8jTP?}x5c8#@5`oNyE|iWZ;zHD0*}+&) z>kGLGJt3Eg;l%m)CmaDO@ENtG2bX47zO_h}dl|cD%!~ykm^lC1@cC!24t=&K6b)p6 z4=&uKEj?gRnos0X`DX-Np^t5R7vP52Zw*xp`}(STTU{)ZhB@mcW^48=e`)Z z_={$1;|q~kNW~-gp%n!+&!b22Z|s{l1yc%&#v`($H~v*;^;l|1f{5L(U;PKvE3bXi z9+?U{7E+(eKGOD&V?NqrTqMhB*;e-B)o9?kg~LgZ*d_t*%<=XQ{|jPZ2!3SA z(^U&427p0f`_kGKlvvYw(?7iYSo^;ZC71*chm)94(51nKmj=Au>%;=7ZClw>>m_`d z9fuYSxQ4Cw{Aj(DuN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GBP?hJ&zYzY9q94XBze;+;CufYFh8_$3l3mRkQUt`5Y!H7Q#Zi1V37I}iMBIpVH z6ApYfuz1nEe_xVS@%C(lj4^9LUuRa|%b`&#OP+ff^=Lz$+I$o?gK_8^F(-n)&SYOS u@(3O+5y)*&T&F~uE~QxAHTNSWhx30XJl{?_N$wi}0000 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 ), @@ -106,13 +133,13 @@ export default class PhotonSprites extends Sprites { 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(); }