Skip to content

BicyclePumpNode

BicyclePumpNode (from scenerystack/scenery-phet) draws a bicycle pump — base, body, handle, hose, and a segmented "remaining capacity" indicator built into the body — and lets the user drag (or keyboard-drag) the handle down to inject discrete units into a model quantity. It's used in sims like States of Matter and Gas Properties to let users add particles one pump-stroke at a time.

ts
import { BicyclePumpNode } from 'scenerystack/scenery-phet';
import { NumberProperty, Property } from 'scenerystack/axon';
import { Range, Vector2 } from 'scenerystack/dot';

A minimal example

ts
const numberOfParticlesProperty = new NumberProperty( 0 );
const rangeProperty = new Property( new Range( 0, 100 ) );

const pumpNode = new BicyclePumpNode( numberOfParticlesProperty, rangeProperty, {
  width: 200,
  height: 250,
  hoseAttachmentOffset: new Vector2( 100, -50 ),
  tandem: tandem.createTandem( 'pumpNode' )
} );

Call pumpNode.reset() from your screen's reset() to snap the handle back to its initial (fully raised) position and clear internal drag-accumulation state — this does not touch numberOfParticlesProperty itself.

Constructor

ts
new BicyclePumpNode(
  numberProperty: TProperty<number>,
  rangeProperty: TReadOnlyProperty<Range>,
  providedOptions?: BicyclePumpNodeOptions
)

numberProperty is incremented as the handle is dragged down; the pump refuses to push numberProperty above rangeProperty.value.max.

Options

OptionDefaultEffect
width / height200 / 250Overall size; every part of the pump is proportioned from these
handleFill / shaftFill / bodyFill / bodyTopFill / baseFill / hoseFillassorted grays/redColors of each visual part
indicatorBackgroundFill / indicatorRemainingFilldark gray / light grayColors of the segmented capacity indicator on the pump body
hoseCurviness1Larger values curve the hose more; smaller values straighten it
hoseAttachmentOffsetVector2(100, 100)Where the hose's far end attaches, relative to the pump's origin; its sign (x > 0 or < 0) decides which side of the cone the hose comes off
nodeEnabledPropertynull (an owned BooleanProperty is created)Pass your own to share enabled-state externally; passing null means the Node owns and disposes its own
injectionEnabledPropertyalways-true BooleanPropertyThrottle: when false, the pump stays visually interactive but stops actually adding particles (for model back-pressure)
numberOfParticlesPerPumpAction10How many full handle-down strokes worth of travel corresponds to one full "pump action" of particle additions
addParticlesOneAtATimetrueIf false, particles accumulated during one stroke are added in a single batch at the end instead of one at a time as the threshold is crossed
handleTouchAreaXDilation / handleTouchAreaYDilation15 / 15Touch-area dilation around the handle
dragListenerOptions / keyboardDragListenerOptionsPassed through to the internal pointer/keyboard drag listeners

Methods

MethodEffect
reset()Returns the handle/shaft to their initial position and clears drag-accumulation state

injectionEnabledProperty vs nodeEnabledProperty

These control two different things: nodeEnabledProperty (or the owned default) governs whether the handle can be grabbed at all — when disabled, the handle dims and stops responding to input. injectionEnabledProperty leaves the handle fully interactive but silently stops incrementing numberProperty, which is the hook meant for "the model can't accept particles this fast" without making the control itself look broken.