easy-scratch/doc/scratch-vm/Scratch3VideoSensingBlocks.html

2734 lines
92 KiB
HTML
Raw Normal View History

2025-02-12 12:27:32 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Scratch3VideoSensingBlocks - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="-_StackFrame.html">_StackFrame</a><ul class='methods'><li data-type='method'><a href="-_StackFrame.html#.create">create</a></li><li data-type='method'><a href="-_StackFrame.html#.release">release</a></li><li data-type='method'><a href="-_StackFrame.html#reset">reset</a></li><li data-type='method'><a href="-_StackFrame.html#reuse">reuse</a></li></ul></li><li><a href="BLE.html">BLE</a><ul class='methods'><li data-type='method'><a href="BLE.html#connectPeripheral">connectPeripheral</a></li><li data-type='method'><a href="BLE.html#didReceiveCall">didReceiveCall</a></li><li data-type='method'><a href="BLE.html#disconnect">disconnect</a></li><li data-type='method'><a href="BLE.html#handleDisconnectError">handleDisconnectError</a></li><li data-type='method'><a href="BLE.html#isConnected">isConnected</a></li><li data-type='method'><a href="BLE.html#read">read</a></li><li data-type='method'><a href="BLE.html#requestPeripheral">requestPeripheral</a></li><li data-type='method'><a href="BLE.html#startNotifications">startNotifications</a></li><li data-type='method'><a href="BLE.html#write">write</a></li></ul></li><li><a href="BlockCached.html">BlockCached</a></li><li><a href="Blocks.html">Blocks</a><ul class='methods'><li data-type='method'><a href="Blocks.html#_addScript">_addScript</a></li><li data-type='method'><a href="Blocks.html#_deleteScript">_deleteScript</a></li><li data-type='method'><a href="Blocks.html#_getBackdropField">_getBackdropField</a></li><li data-type='method'><a href="Blocks.html#_getBlockParams">_getBlockParams</a></li><li data-type='method'><a href="Blocks.html#_getCostumeField">_getCostumeField</a></li><li data-type='method'><a href="Blocks.html#_getCustomBlockInternal">_getCustomBlockInternal</a></li><li data-type='method'><a href="Blocks.html#_getSoundField">_getSoundField</a></li><li data-type='method'><a href="Blocks.html#_getSpriteField">_getSpriteField</a></li><li data-type='method'><a href="Blocks.html#blocklyListen">blocklyListen</a></li><li data-type='method'><a href="Blocks.html#blockToXML">blockToXML</a></li><li data-type='method'><a href="Blocks.html#changeBlock">changeBlock</a></li><li data-type='method'><a href="Blocks.html#createBlock">createBlock</a></li><li data-type='method'><a href="Blocks.html#deleteBlock">deleteBlock</a></li><li data-type='method'><a href="Blocks.html#emitProjectChanged">emitProjectChanged</a></li><li data-type='method'><a href="Blocks.html#getAllVariableAndListReferences">getAllVariableAndListReferences</a></li><li data-type='method'><a href="Blocks.html#getBlock">getBlock</a></li><li data-type='method'><a href="Blocks.html#getBranch">getBranch</a></li><li data-type='method'><a href="Blocks.html#getFields">getFields</a></li><li data-type='method'><a href="Blocks.html#getInputs">getInputs</a></li><li data-type='method'><a href="Blocks.html#getMutation">getMutation</a></li><li data-type='method'><a href="Blocks.html#getNextBlock">getNextBlock</a></li><li data-type='method'><a href="Blocks.html#getOpcode">getOpcode</a></li><li data-type='method'><a href="Blocks.html#getProcedureDefinition">getProcedureDefinition</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesAndIds">getProcedureParamNamesAndIds</a></li><li data-type='method'><a href="Blocks.html#getProcedureParamNamesIdsAndDefaults">getProcedureParamNamesIdsAndDefaults</a></li><li data-type='method'><a href="Blocks.html#getScripts">getScripts</a></li><li data-type='method'><a href="Blocks.html#getTopLevelScript">getTopLevelScript</a></li><li data-type='method'><a href="Blocks.html#moveBlock">moveBlock</a></li><li data-type='method'><a href="Blocks.html#mutationToXML">mutationToXML</a></li><li data-type='method'><a href="Blocks.html#resetCache">resetCache</a></li><li data-type='method'><a href="Blocks.html#runAllMonitored">runAllMonitored</a></li><li data-type='method'><a href="Blocks.html#toXML">toXML</a></li><li data-type='method'><a href="Blocks.html#updateAssetName">updateAssetName</a></li><li data-type='method'><a href
</nav>
<div id="main">
<h1 class="page-title">Scratch3VideoSensingBlocks</h1>
<section>
<header>
<h2>
Scratch3VideoSensingBlocks
</h2>
<div class="class-description"><p>Class for the motion-related blocks in Scratch 3.0</p></div>
</header>
<article>
<div class="container-overview">
<h2>Constructor</h2>
<h4 class="name" id="Scratch3VideoSensingBlocks"><span class="type-signature"></span>new Scratch3VideoSensingBlocks<span class="signature">(runtime)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>runtime</code></td>
<td class="type">
<span class="param-type"><a href="Runtime.html">Runtime</a></span>
</td>
<td class="description last"><p>the runtime instantiating this block package.</p></td>
</tr>
</tbody>
</table>
</div>
<h3 class="subsection-title">Members</h3>
<h4 class="name" id=".DEFAULT_MOTION_STATE"><span class="type-signature">(static) </span>DEFAULT_MOTION_STATE<span class="type-signature"> :MotionState</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The default motion-related state, to be used when a target has no existing motion state.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">MotionState</span>
</li>
</ul>
<h4 class="name" id=".DIMENSIONS"><span class="type-signature">(static) </span>DIMENSIONS<span class="type-signature"> :Array.&lt;number></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Dimensions the video stream is analyzed at after its rendered to the
sample canvas.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Array.&lt;number></span>
</li>
</ul>
<h4 class="name" id=".INTERVAL"><span class="type-signature">(static) </span>INTERVAL<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>After analyzing a frame the amount of milliseconds until another frame
is analyzed.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id=".STATE_KEY"><span class="type-signature">(static) </span>STATE_KEY<span class="type-signature"> :string</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The key to load &amp; store a target's motion-related state.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<h4 class="name" id=".VideoState"><span class="type-signature">(static, readonly) </span>VideoState<span class="type-signature"> :string</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>States the video sensing activity can be set to.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">string</span>
</li>
</ul>
<h4 class="name" id="_lastUpdate"><span class="type-signature"></span>_lastUpdate<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The last millisecond epoch timestamp that the video stream was
analyzed.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="ATTRIBUTE_INFO"><span class="type-signature"></span>ATTRIBUTE_INFO<span class="type-signature"> :Array.&lt;object></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>An array of choices of whether a reporter should return the frame's
motion amount or direction.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Array.&lt;object></span>
</li>
</ul>
<h4 class="name" id="detect"><span class="type-signature"></span>detect<span class="type-signature"> :<a href="VideoMotion.html">VideoMotion</a></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The motion detection algoritm used to power the motion amount and
direction values.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="VideoMotion.html">VideoMotion</a></span>
</li>
</ul>
<h4 class="name" id="firstInstall"><span class="type-signature"></span>firstInstall<span class="type-signature"> :boolean</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>A flag to determine if this extension has been installed in a project.
It is set to false the first time getInfo is run.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">boolean</span>
</li>
</ul>
<h4 class="name" id="globalVideoState"><span class="type-signature"></span>globalVideoState<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The video state of the video preview stored in a value accessible by any
object connected to the virtual machine.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="globalVideoTransparency"><span class="type-signature"></span>globalVideoTransparency<span class="type-signature"> :number</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The transparency setting of the video preview stored in a value
accessible by any object connected to the virtual machine.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">number</span>
</li>
</ul>
<h4 class="name" id="runtime"><span class="type-signature"></span>runtime<span class="type-signature"> :<a href="Runtime.html">Runtime</a></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>The runtime instantiating this block package.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type"><a href="Runtime.html">Runtime</a></span>
</li>
</ul>
<h4 class="name" id="SUBJECT_INFO"><span class="type-signature"></span>SUBJECT_INFO<span class="type-signature"> :Array.&lt;object></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>An array of info about the subject choices.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Array.&lt;object></span>
</li>
</ul>
<h4 class="name" id="VIDEO_STATE_INFO"><span class="type-signature"></span>VIDEO_STATE_INFO<span class="type-signature"> :Array.&lt;object></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>An array of info on video state options for the &quot;turn video [STATE]&quot; block.</p>
</div>
<h5>Type:</h5>
<ul>
<li>
<span class="param-type">Array.&lt;object></span>
</li>
</ul>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="_analyzeLocalMotion"><span class="type-signature"></span>_analyzeLocalMotion<span class="signature">(target)</span><span class="type-signature"> &rarr; {MotionState}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Analyze a part of the frame that a target overlaps.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>target</code></td>
<td class="type">
<span class="param-type"><a href="Target.html">Target</a></span>
</td>
<td class="description last"><p>a target to determine where to analyze</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>the motion state for the given target</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">MotionState</span>
</dd>
</dl>
<h4 class="name" id="_buildMenu"><span class="type-signature">(private) </span>_buildMenu<span class="signature">(info)</span><span class="type-signature"> &rarr; {array}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>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.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>info</code></td>
<td class="type">
<span class="param-type">Array.&lt;object></span>
</td>
<td class="description last"><p>An array of info objects each having a name
property.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<ul>
<li>An array of objects with text and value properties.</li>
</ul>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">array</span>
</dd>
</dl>
<h4 class="name" id="_getMotionState"><span class="type-signature">(private) </span>_getMotionState<span class="signature">(target)</span><span class="type-signature"> &rarr; {MotionState}</span></h4>
<dl class="details">
</dl>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>target</code></td>
<td class="type">
<span class="param-type"><a href="Target.html">Target</a></span>
</td>
<td class="description last"><p>collect motion state for this target.</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>the mutable motion state associated with that
target. This will be created if necessary.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">MotionState</span>
</dd>
</dl>
<h4 class="name" id="_loop"><span class="type-signature">(private) </span>_loop<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>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.</p>
</div>
<h4 class="name" id="getInfo"><span class="type-signature"></span>getInfo<span class="signature">()</span><span class="type-signature"> &rarr; {object}</span></h4>
<dl class="details">
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>metadata for this extension and its blocks.</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">object</span>
</dd>
</dl>
<h4 class="name" id="reset"><span class="type-signature"></span>reset<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>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.</p>
</div>
<h4 class="name" id="setVideoTransparency"><span class="type-signature"></span>setVideoTransparency<span class="signature">(args)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>A scratch command block handle that configures the video preview's
transparency from passed arguments.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block arguments</p>
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>TRANSPARENCY</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>the transparency to set the video
preview to</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<h4 class="name" id="updateVideoDisplay"><span class="type-signature"></span>updateVideoDisplay<span class="signature">()</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>Get the latest values for video transparency and state,
and set the video device to use them.</p>
</div>
<h4 class="name" id="videoOn"><span class="type-signature"></span>videoOn<span class="signature">(args, util)</span><span class="type-signature"> &rarr; {number}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>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.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block arguments</p></td>
</tr>
<tr>
<td class="name"><code>util</code></td>
<td class="type">
<span class="param-type"><a href="BlockUtility.html">BlockUtility</a></span>
</td>
<td class="description last"><p>the block utility</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>the motion amount or direction of the stage or sprite</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">number</span>
</dd>
</dl>
<h4 class="name" id="videoToggle"><span class="type-signature"></span>videoToggle<span class="signature">(args)</span><span class="type-signature"></span></h4>
<dl class="details">
</dl>
<div class="description">
<p>A scratch command block handle that configures the video state from
passed arguments.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block arguments</p>
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>VIDEO_STATE</code></td>
<td class="type">
<span class="param-type"><a href="global.html#VideoState">VideoState</a></span>
</td>
<td class="description last"><p>the video state to set the device to</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<h4 class="name" id="whenMotionGreaterThan"><span class="type-signature"></span>whenMotionGreaterThan<span class="signature">(args, util)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
<dl class="details">
</dl>
<div class="description">
<p>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.</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>args</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>the block arguments</p></td>
</tr>
<tr>
<td class="name"><code>util</code></td>
<td class="type">
<span class="param-type"><a href="BlockUtility.html">BlockUtility</a></span>
</td>
<td class="description last"><p>the block utility</p></td>
</tr>
</tbody>
</table>
<h5>Returns:</h5>
<div class="param-desc">
<p>true if the sprite overlaps more motion than the
reference</p>
</div>
<dl class="param-type">
<dt>
Type
</dt>
<dd>
<span class="param-type">boolean</span>
</dd>
</dl>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
</body>
</html>