Scratch3VideoSensingBlocks

Scratch3VideoSensingBlocks

Class for the motion-related blocks in Scratch 3.0

Constructor

new Scratch3VideoSensingBlocks(runtime)

Parameters:
Name Type Description
runtime Runtime

the runtime instantiating this block package.

Members

(static) DEFAULT_MOTION_STATE :MotionState

The default motion-related state, to be used when a target has no existing motion state.

Type:
  • MotionState

(static) DIMENSIONS :Array.<number>

Dimensions the video stream is analyzed at after its rendered to the sample canvas.

Type:
  • Array.<number>

(static) INTERVAL :number

After analyzing a frame the amount of milliseconds until another frame is analyzed.

Type:
  • number

(static) STATE_KEY :string

The key to load & store a target's motion-related state.

Type:
  • string

(static, readonly) VideoState :string

States the video sensing activity can be set to.

Type:
  • string

_lastUpdate :number

The last millisecond epoch timestamp that the video stream was analyzed.

Type:
  • number

ATTRIBUTE_INFO :Array.<object>

An array of choices of whether a reporter should return the frame's motion amount or direction.

Type:
  • Array.<object>

detect :VideoMotion

The motion detection algoritm used to power the motion amount and direction values.

Type:

firstInstall :boolean

A flag to determine if this extension has been installed in a project. It is set to false the first time getInfo is run.

Type:
  • boolean

globalVideoState :number

The video state of the video preview stored in a value accessible by any object connected to the virtual machine.

Type:
  • number

globalVideoTransparency :number

The transparency setting of the video preview stored in a value accessible by any object connected to the virtual machine.

Type:
  • number

runtime :Runtime

The runtime instantiating this block package.

Type:

SUBJECT_INFO :Array.<object>

An array of info about the subject choices.

Type:
  • Array.<object>

VIDEO_STATE_INFO :Array.<object>

An array of info on video state options for the "turn video [STATE]" block.

Type:
  • Array.<object>

Methods

_analyzeLocalMotion(target) → {MotionState}

Analyze a part of the frame that a target overlaps.

Parameters:
Name Type Description
target Target

a target to determine where to analyze

Returns:

the motion state for the given target

Type
MotionState

(private) _buildMenu(info) → {array}

Create data for a menu in scratch-blocks format, consisting of an array of objects with text and value properties. The text is a translated string, and the value is one-indexed.

Parameters:
Name Type Description
info Array.<object>

An array of info objects each having a name property.

Returns:
  • An array of objects with text and value properties.
Type
array

(private) _getMotionState(target) → {MotionState}

Parameters:
Name Type Description
target Target

collect motion state for this target.

Returns:

the mutable motion state associated with that target. This will be created if necessary.

Type
MotionState

(private) _loop()

Occasionally step a loop to sample the video, stamp it to the preview skin, and add a TypedArray copy of the canvas's pixel data.

getInfo() → {object}

Returns:

metadata for this extension and its blocks.

Type
object

reset()

Reset the extension's data motion detection data. This will clear out for example old frames, so the first analyzed frame will not be compared against a frame from before reset was called.

setVideoTransparency(args)

A scratch command block handle that configures the video preview's transparency from passed arguments.

Parameters:
Name Type Description
args object

the block arguments

Properties
Name Type Description
TRANSPARENCY number

the transparency to set the video preview to

updateVideoDisplay()

Get the latest values for video transparency and state, and set the video device to use them.

videoOn(args, util) → {number}

A scratch reporter block handle that analyzes the last two frames and depending on the arguments, returns the motion or direction for the whole stage or just the target sprite.

Parameters:
Name Type Description
args object

the block arguments

util BlockUtility

the block utility

Returns:

the motion amount or direction of the stage or sprite

Type
number

videoToggle(args)

A scratch command block handle that configures the video state from passed arguments.

Parameters:
Name Type Description
args object

the block arguments

Properties
Name Type Description
VIDEO_STATE VideoState

the video state to set the device to

whenMotionGreaterThan(args, util) → {boolean}

A scratch hat block edge handle that analyzes the last two frames where the target sprite overlaps and if it has more motion than the given reference value.

Parameters:
Name Type Description
args object

the block arguments

util BlockUtility

the block utility

Returns:

true if the sprite overlaps more motion than the reference

Type
boolean