added 'name' selector to pixel library

upd4.2
jmoenig 2018-04-24 08:15:31 +02:00
rodzic e3743028c0
commit 3abc58bd6e
2 zmienionych plików z 7 dodań i 2 usunięć

Wyświetl plik

@ -4082,3 +4082,7 @@ in development:
------
* Blocks: only preserve filled rings when collapsing ring-typed multi-arg-slots
* Blocks: minor tweaks
180424
------
* added 'name' selector to pixel library

Wyświetl plik

@ -1,3 +1,4 @@
<blocks app="Snap! 4.1, http://snap.berkeley.edu" version="1"><block-definition s="%&apos;attribute&apos; of %&apos;costume&apos;" type="reporter" category="looks"><comment w="187" collapsed="false">reports a list of all pixels in the given costume. Each pixel is represented by a 4-item sublist of RGBA values</comment><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true">pixels<options>pixels
<blocks app="Snap! 4.1, http://snap.berkeley.edu" version="1"><block-definition s="%&apos;attribute&apos; of %&apos;costume&apos;" type="reporter" category="looks"><comment w="187" collapsed="false">reports a list of all pixels in the given costume. Each pixel is represented by a 4-item sublist of RGBA values</comment><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true">pixels<options>name
pixels
width
height</options></input><input type="%obj"></input></inputs><script><block s="doIf"><block s="reportEquals"><block var="attribute"/><l>width</l></block><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>costume</l></list><l>return costume.contents.width;</l></block><list><block var="costume"/></list></block></block></script></block><block s="doIf"><block s="reportEquals"><block var="attribute"/><l>height</l></block><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>costume</l></list><l>return costume.contents.height;</l></block><list><block var="costume"/></list></block></block></script></block><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>costume</l></list><l> var i,&#xD; pixels = [],&#xD; src = costume.contents.getContext(&apos;2d&apos;).getImageData(&#xD; 0,&#xD; 0,&#xD; costume.width(),&#xD; costume.height()&#xD; );&#xD; for (i = 0; i &lt; src.data.length; i += 4) {&#xD; pixels.push(new List([&#xD; src.data[i],&#xD; src.data[i + 1],&#xD; src.data[i + 2],&#xD; src.data[i + 3]&#xD; ]));&#xD; }&#xD; return new List(pixels);</l></block><list><block var="costume"/></list></block></block></script></block-definition><block-definition s="update %&apos;costume&apos; with %&apos;pixels&apos;" type="command" category="looks"><comment x="0" y="0" w="286" collapsed="false">overwrite the pixels in the given costume with another list of pixels.&#xD;&#xD;Caution! This operation directly changes the costume. Make sure to use a copy in case you would like to revert changes later.</comment><header></header><code></code><translations></translations><inputs><input type="%obj"></input><input type="%l"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>costume</l><l>pixels</l></list><l> var i, k,&#xD; ctx = costume.contents.getContext(&apos;2d&apos;),&#xD; src = pixels.asArray(),&#xD; dta = ctx.createImageData(costume.width(), costume.height());&#xD; for (i = 0; i &lt; src.length; i += 1) {&#xD; px = src[i].asArray();&#xD; for (k = 0; k &lt; 4; k += 1) {&#xD; dta.data[(i * 4) + k] = px[k];&#xD; }&#xD; }&#xD; ctx.putImageData(dta, 0, 0);</l></block><list><block var="costume"/><block var="pixels"/></list></block></script></block-definition><block-definition s="current costume" type="reporter" category="sensing"><comment w="178" collapsed="false">reports the sprite&apos;s actual current costume, which may or may not be part of its wardrobe e.g. if it is a copy</comment><header></header><code></code><translations></translations><inputs></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list></list><l>return this.costume;</l></block><list></list></block></block></script></block-definition><block-definition s="copy of %&apos;costume&apos;" type="reporter" category="looks"><comment x="0" y="0" w="206" collapsed="false">reports a copy of the given costume. This is especially useful when modifying a costume, so you can keep the original around</comment><header></header><code></code><translations></translations><inputs><input type="%obj"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>costume</l></list><l>return costume.copy();</l></block><list><block var="costume"/></list></block></block></script></block-definition><block-definition s="show picture %&apos;bitmap&apos;" type="command" category="looks"><comment x="0" y="0" w="88" collapsed="false">display the given bitmap in a copy of the current costume (so you can switch back to the original costume again)</comment><header></header><code></code><translations></translations><inputs><input type="%l"></input></inputs><script><custom-block s="let %upvar be %s"><l>copy</l><custom-block s="copy of %obj"><custom-block s="current costume"></custom-block></custom-block></custom-block><custom-block s="update %obj with %l"><block var="copy"/><block var="bitmap"/></custom-block><block s="doSwitchToCostume"><block var="copy"/></block></script></block-definition><block-definition s="let %&apos;var&apos; be %&apos;value&apos;" type="command" category="other"><header></header><code></code><translations></translations><inputs><input type="%upvar"></input><input type="%s"></input></inputs><script><block s="doSetVar"><l>var</l><block var="value"/></block></script></block-definition></blocks>
height</options></input><input type="%obj"></input></inputs><script><block s="doIf"><block s="reportEquals"><block var="attribute"/><l>name</l></block><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>costume</l></list><l>return costume.name;</l></block><list><block var="costume"/></list></block></block></script></block><block s="doIf"><block s="reportEquals"><block var="attribute"/><l>width</l></block><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>costume</l></list><l>return costume.contents.width;</l></block><list><block var="costume"/></list></block></block></script></block><block s="doIf"><block s="reportEquals"><block var="attribute"/><l>height</l></block><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>costume</l></list><l>return costume.contents.height;</l></block><list><block var="costume"/></list></block></block></script></block><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>costume</l></list><l> var i,&#xD; pixels = [],&#xD; src = costume.contents.getContext(&apos;2d&apos;).getImageData(&#xD; 0,&#xD; 0,&#xD; costume.width(),&#xD; costume.height()&#xD; );&#xD; for (i = 0; i &lt; src.data.length; i += 4) {&#xD; pixels.push(new List([&#xD; src.data[i],&#xD; src.data[i + 1],&#xD; src.data[i + 2],&#xD; src.data[i + 3]&#xD; ]));&#xD; }&#xD; return new List(pixels);</l></block><list><block var="costume"/></list></block></block></script></block-definition><block-definition s="update %&apos;costume&apos; with %&apos;pixels&apos;" type="command" category="looks"><comment x="0" y="0" w="286" collapsed="false">overwrite the pixels in the given costume with another list of pixels.&#xD;&#xD;Caution! This operation directly changes the costume. Make sure to use a copy in case you would like to revert changes later.</comment><header></header><code></code><translations></translations><inputs><input type="%obj"></input><input type="%l"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>costume</l><l>pixels</l></list><l> var i, k,&#xD; ctx = costume.contents.getContext(&apos;2d&apos;),&#xD; src = pixels.asArray(),&#xD; dta = ctx.createImageData(costume.width(), costume.height());&#xD; for (i = 0; i &lt; src.length; i += 1) {&#xD; px = src[i].asArray();&#xD; for (k = 0; k &lt; 4; k += 1) {&#xD; dta.data[(i * 4) + k] = px[k];&#xD; }&#xD; }&#xD; ctx.putImageData(dta, 0, 0);</l></block><list><block var="costume"/><block var="pixels"/></list></block></script></block-definition><block-definition s="current costume" type="reporter" category="sensing"><comment x="0" y="0" w="178" collapsed="false">reports the sprite&apos;s actual current costume, which may or may not be part of its wardrobe e.g. if it is a copy</comment><header></header><code></code><translations></translations><inputs></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list></list><l>return this.costume;</l></block><list></list></block></block></script></block-definition><block-definition s="copy of %&apos;costume&apos;" type="reporter" category="looks"><comment x="0" y="0" w="206" collapsed="false">reports a copy of the given costume. This is especially useful when modifying a costume, so you can keep the original around</comment><header></header><code></code><translations></translations><inputs><input type="%obj"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>costume</l></list><l>return costume.copy();</l></block><list><block var="costume"/></list></block></block></script></block-definition><block-definition s="show picture %&apos;bitmap&apos;" type="command" category="looks"><comment x="0" y="0" w="88" collapsed="false">display the given bitmap in a copy of the current costume (so you can switch back to the original costume again)</comment><header></header><code></code><translations></translations><inputs><input type="%l"></input></inputs><script><custom-block s="let %upvar be %s"><l>copy</l><custom-block s="copy of %obj"><custom-block s="current costume"></custom-block></custom-block></custom-block><custom-block s="update %obj with %l"><block var="copy"/><block var="bitmap"/></custom-block><block s="doSwitchToCostume"><block var="copy"/></block></script></block-definition><block-definition s="let %&apos;var&apos; be %&apos;value&apos;" type="command" category="other"><header></header><code></code><translations></translations><inputs><input type="%upvar"></input><input type="%s"></input></inputs><script><block s="doSetVar"><l>var</l><block var="value"/></block></script></block-definition></blocks>