-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out MagnifyingGlassNode, see phetsims/circuit-construction-kit…
- Loading branch information
Showing
2 changed files
with
63 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2020, University of Colorado Boulder | ||
|
||
import merge from '../../phet-core/js/merge.js'; | ||
import Circle from '../../scenery/js/nodes/Circle.js'; | ||
import Line from '../../scenery/js/nodes/Line.js'; | ||
import Node from '../../scenery/js/nodes/Node.js'; | ||
import sceneryPhet from './sceneryPhet.js'; | ||
|
||
/** | ||
* | ||
* @author Sam Reid (PhET Interactive Simulations) | ||
*/ | ||
|
||
class MagnifyingGlassNode extends Node { | ||
|
||
constructor( options ) { | ||
|
||
options = merge( { | ||
glassRadius: 15, | ||
glassFill: 'white', // center of the glass | ||
glassStroke: 'black', // rim and handle | ||
icon: null // optional icon will be centered in the glass area, if provided | ||
}, options ); | ||
|
||
// the magnifying glass | ||
const glassLineWidth = 0.25 * options.glassRadius; | ||
const glassNode = new Circle( options.glassRadius, { | ||
fill: options.glassFill, | ||
stroke: options.glassStroke, | ||
lineWidth: glassLineWidth | ||
} ); | ||
|
||
// handle at lower-left of glass, at a 45-degree angle | ||
const outsideRadius = options.glassRadius + ( glassLineWidth / 2 ); // use outside radius so handle line cap doesn't appear inside glassNode | ||
const handleNode = new Line( | ||
outsideRadius * Math.cos( Math.PI / 4 ), outsideRadius * Math.sin( Math.PI / 4 ), | ||
options.glassRadius * Math.cos( Math.PI / 4 ) + ( 0.65 * options.glassRadius ), options.glassRadius * Math.sin( Math.PI / 4 ) + ( 0.65 * options.glassRadius ), { | ||
stroke: options.glassStroke, | ||
lineWidth: 0.4 * options.glassRadius, | ||
lineCap: 'round' | ||
} ); | ||
|
||
options.children = [ glassNode, handleNode ]; | ||
|
||
if ( options.icon ) { | ||
options.icon.center = glassNode.center; | ||
options.children.push( options.icon ); | ||
} | ||
|
||
super( options ); | ||
} | ||
} | ||
|
||
sceneryPhet.register( 'MagnifyingGlassNode', MagnifyingGlassNode ); | ||
export default MagnifyingGlassNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters