Skip to content

Commit

Permalink
group static images together, add a comment linking to this issue, #113
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Mar 26, 2024
1 parent f277090 commit fb7bcb6
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions js/common/view/FieldNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export default class FieldNode extends Sprites {

public constructor( magnet: Magnet, visibleBoundsProperty: TReadOnlyProperty<Bounds2>, tandem: Tandem ) {

// A vector in the field is visualized as a compass needle.
const sprite = new Sprite( FieldNode.getSpriteImage(
FELColors.compassNeedleNorthColorProperty.value,
FELColors.compassNeedleSouthColorProperty.value
Expand Down Expand Up @@ -81,31 +80,6 @@ export default class FieldNode extends Sprites {
this.addLinkedElement( magnet );
}

private static getSpriteImage( compassNeedleNorthColor: Color, compassNeedleSouthColor: Color ): SpriteImage {
// A vector in the field is visualized as a compass needle.
// Convert a CompassNeedleNode to a Sprite.
const compassNeedleNode = new CompassNeedleNode( {
northFill: compassNeedleNorthColor,
southFill: compassNeedleSouthColor,

// Apply a scale to increase resolution (we'll apply the inverse scale when rendering).
scale: COMPASS_NEEDLE_RESOLUTION_MULTIPLIER
} );

let spriteImage!: SpriteImage;

compassNeedleNode.toCanvas( ( canvas, x, y, width, height ) => {
spriteImage = new SpriteImage( canvas, new Vector2( ( x + compassNeedleNode.width / 2 ), ( y + compassNeedleNode.height / 2 ) ), {
// It looked too "sharp" without mipmapping at the normal view distance, so we'll have these generated.
mipmap: true,
mipmapBias: -0.7
} );
} );

assert && assert( spriteImage );
return spriteImage;
}

/**
* Rebuilds the grid to fill the visible bounds of the browser. We're not bothering with SpriteInstance pooling
* because this happens rarely, and the time to rebuild is not noticeable.
Expand Down Expand Up @@ -163,6 +137,36 @@ export default class FieldNode extends Sprites {
assert && assert( normalizedMagnitude >= 0 && normalizedMagnitude <= 1, `invalid normalizedStrength: ${normalizedMagnitude}` );
return normalizedMagnitude;
}

/**
* Gets the SpriteImage used to visualize a point in the field -- a compass needle.
*/
private static getSpriteImage( compassNeedleNorthColor: Color, compassNeedleSouthColor: Color ): SpriteImage {

// Convert a CompassNeedleNode to a Sprite.
const compassNeedleNode = new CompassNeedleNode( {
northFill: compassNeedleNorthColor,
southFill: compassNeedleSouthColor,

// Apply a scale to increase resolution (we'll apply the inverse scale when rendering).
scale: COMPASS_NEEDLE_RESOLUTION_MULTIPLIER
} );

let spriteImage!: SpriteImage;

compassNeedleNode.toCanvas( ( canvas, x, y, width, height ) => {
spriteImage = new SpriteImage( canvas, new Vector2( ( x + compassNeedleNode.width / 2 ), ( y + compassNeedleNode.height / 2 ) ), {

// Mipmapping was added to address pixelation reported in https://github.com/phetsims/faradays-electromagnetic-lab/issues/113.
// It looked too "sharp" without mipmapping at the normal view distance, so we'll have these generated.
mipmap: true,
mipmapBias: -0.7
} );
} );

assert && assert( spriteImage );
return spriteImage;
}
}

/**
Expand Down

0 comments on commit fb7bcb6

Please sign in to comment.