Skip to content

Commit

Permalink
Taking care of how coinSetInTestBoxProperty is set, see #47
Browse files Browse the repository at this point in the history
  • Loading branch information
AgustinVallejo committed Oct 3, 2024
1 parent 8a1edea commit 1ac74d2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
1 change: 1 addition & 0 deletions js/coins/view/CoinExperimentMeasurementArea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export default class CoinExperimentMeasurementArea extends VBox {
const measuredCoinsPixelRepresentation = new CoinSetPixelRepresentation(
sceneModel.systemType,
sceneModel.coinSet.measurementStateProperty,
coinSetInTestBoxProperty,
{
visibleProperty: new DerivedProperty( [
sceneModel.coinSet.numberOfActiveSystemsProperty,
Expand Down
18 changes: 14 additions & 4 deletions js/coins/view/CoinSetPixelRepresentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*
*/

import TProperty from '../../../../axon/js/TProperty.js';
import TReadOnlyProperty from '../../../../axon/js/TReadOnlyProperty.js';
import dotRandom from '../../../../dot/js/dotRandom.js';
import { CanvasNode, CanvasNodeOptions } from '../../../../scenery/js/imports.js';
Expand All @@ -28,6 +29,7 @@ export default class CoinSetPixelRepresentation extends CanvasNode {
public constructor(
private readonly systemType: 'classical' | 'quantum',
private readonly experimentStateProperty: TReadOnlyProperty<ExperimentMeasurementState>,
private readonly coinSetInTestBoxProperty: TProperty<boolean>,
providedOptions?: CanvasNodeOptions
) {
super( providedOptions );
Expand Down Expand Up @@ -90,6 +92,7 @@ export default class CoinSetPixelRepresentation extends CanvasNode {
this.populatingAnimation.finishEmitter.addListener( () => {
this.setAllPixels( 1 );
this.currentFrame = 0;
this.coinSetInTestBoxProperty.value = true;
} );

this.flippingAnimation.finishEmitter.addListener( () => {
Expand Down Expand Up @@ -173,14 +176,18 @@ export default class CoinSetPixelRepresentation extends CanvasNode {
}

public startPopulatingAnimation(): void {
// Set all pixels to 0
this.setAllPixels( 0 );
if ( this.visible ) {
// Set all pixels to 0
this.setAllPixels( 0 );

this.populatingAnimation.start();
this.populatingAnimation.start();
}
}

public startFlippingAnimation(): void {
this.flippingAnimation.start();
if ( this.visible ) {
this.flippingAnimation.start();
}
}

/**
Expand All @@ -191,6 +198,9 @@ export default class CoinSetPixelRepresentation extends CanvasNode {
this.populatingAnimation.stop();
this.currentFrame = 0;
this.setAllPixels( pixelState );

// Set the flag to indicate that the coins aren't in the box.
this.coinSetInTestBoxProperty.value = false;
}

public setAllPixels( value: number ): void {
Expand Down
18 changes: 13 additions & 5 deletions js/coins/view/MultipleCoinAnimations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ public readonly startIngressAnimationForCoinSet: ( forReprepare: boolean ) => vo
// Create the nodes that will be used to animate coin motion for the multiple coin experiments. These are sized
// differently based on the quantity being animated.
const movingCoinNodes = new Map<number, SmallCoinNode[]>();
MULTI_COIN_EXPERIMENT_QUANTITIES.forEach( quantity => {

// The 10000 coins case will be animated separately
const ANIMATION_QUANTITIES = MULTI_COIN_EXPERIMENT_QUANTITIES.filter( quantity => quantity !== 10000 );
ANIMATION_QUANTITIES.forEach( quantity => {
const quantityToCreate = Math.min( quantity, QuantumMeasurementConstants.HOLLYWOODED_MAX_COINS );
const radius = MultiCoinTestBox.getRadiusFromCoinQuantity( quantity );
const coinNodes: SmallCoinNode[] = [];
Expand All @@ -65,6 +68,10 @@ public readonly startIngressAnimationForCoinSet: ( forReprepare: boolean ) => vo
animationsToEdgeOfMultiCoinTestBox.forEach( animation => animation.stop() );
animationsFromEdgeOfMultiCoinBoxToInside.forEach( animation => animation.stop() );

// Remove the animations from the list of active ones.
animationsToEdgeOfMultiCoinTestBox.length = 0;
animationsFromEdgeOfMultiCoinBoxToInside.length = 0;

// Clear out any coins that made it to the test box.
multipleCoinTestBox.clearContents();

Expand All @@ -73,22 +80,23 @@ public readonly startIngressAnimationForCoinSet: ( forReprepare: boolean ) => vo
sceneGraphParent.removeChild( smallCoinNode );
} );

// Set the flag to indicate that the coins are not in the box.
// Set the flag to indicate that the coins aren't in the box.
coinSetInTestBoxProperty.value = false;
};

this.startIngressAnimationForCoinSet = ( forReprepare: boolean ) => {

if ( sceneModel.coinSet.numberOfActiveSystemsProperty.value === 10000 ) {
return;
}

// Create a typed reference to the parent node, since we'll need to invoke some methods on it.
assert && assert( measurementArea.getParent() instanceof CoinsExperimentSceneView );
const sceneGraphParent = measurementArea.getParent() as CoinsExperimentSceneView;

// Make sure the test box is empty.
multipleCoinTestBox.clearContents();

// Set the flag to indicate that the coins aren't in the box.
coinSetInTestBoxProperty.value = false;

assert && assert(
movingCoinNodes.has( sceneModel.coinSet.numberOfActiveSystemsProperty.value ),
'No coin nodes exist for the needed quantity.'
Expand Down

0 comments on commit 1ac74d2

Please sign in to comment.