Skip to content

FaucetNode

FaucetNode (from scenerystack/scenery-phet) draws a faucet whose interactive part is a "shooter" that behaves like a horizontal slider — sliding it out increases a flowRateProperty, and the visuals (pipe, spout, track, knob) are all pre-built PNG-based image assets. It's used in fluid/flow sims like pH Scale and Molarity wherever the user needs to turn on a flow of something.

ts
import { FaucetNode } from 'scenerystack/scenery-phet';
import { Property } from 'scenerystack/axon';

A minimal example

ts
const maxFlowRate = 10; // L/s
const flowRateProperty = new Property( 0 );
const enabledProperty = new Property( true );

const faucetNode = new FaucetNode( maxFlowRate, flowRateProperty, enabledProperty, {
  tandem: tandem.createTandem( 'faucetNode' )
} );

FaucetNode's origin is the bottom-center of its spout, which makes it easy to align against wherever fluid should visually emerge.

Constructor

ts
new FaucetNode(
  maxFlowRate: number,
  flowRateProperty: Property<number>,
  enabledProperty: TReadOnlyProperty<boolean>,
  providedOptions?: FaucetNodeOptions
)

FaucetNode extends AccessibleSlider, so flowRateProperty also drives keyboard alt-input the same way a slider's value would.

Options

OptionDefaultEffect
horizontalPipeLengthspout's x-centerDistance from the left edge of the horizontal pipe to the spout's center
verticalPipeLength43Length of the vertical pipe connecting the body to the spout
closeOnReleasetrueIf true, releasing the shooter always sets flow to zero ("close-on-release"); if false, it stays wherever released ("slider mode")
tapToDispenseEnabledtrueTapping the shooter without dragging toggles a burst of flow on/off
tapToDispenseAmount0.25 * maxFlowRateAmount dispensed per tap, in L
tapToDispenseInterval500Duration (ms) that a tap-to-dispense burst runs
interactivePropertyalways-true PropertyWhen false, hides the shooter and track entirely (the flow control becomes non-interactive)
rasterizeHorizontalPipeNodefalseRasterizes the tiled horizontal pipe image, to work around flickering seen in some sims
grabSoundPlayer / releaseSoundPlayershared grab/release soundsSounds played on drag-start / on flow reaching zero
shooterOptionsOptions for the internal shooter (e.g. knobScale, touch/mouse area dilation)

closeOnRelease defaults to true

Out of the box, dragging the shooter and letting go snaps the flow rate back to zero — it is not slider-like persistence by default. If you want the faucet to stay open at whatever rate the user left it at (as with a real tap), you must explicitly pass closeOnRelease: false.