kopia lustrzana https://github.com/backface/turtlestitch
4 wiersze
6.5 KiB
XML
4 wiersze
6.5 KiB
XML
<blocks app="Snap! 4.2, http://snap.berkeley.edu" version="1"><block-definition s="%'attribute' of costume %'costume'" 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>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,
 pixels = [],
 src = costume.contents.getContext('2d').getImageData(
 0,
 0,
 costume.width(),
 costume.height()
 );
 for (i = 0; i < src.data.length; i += 4) {
 pixels.push(new List([
 src.data[i],
 src.data[i + 1],
 src.data[i + 2],
 src.data[i + 3]
 ]));
 }
 return new List(pixels);</l></block><list><block var="costume"/></list></block></block></script></block-definition><block-definition s="update %'costume' with %'pixels'" 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.

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,
 ctx = costume.contents.getContext('2d'),
 src = pixels.asArray(),
 dta = ctx.createImageData(costume.width(), costume.height());
 for (i = 0; i < src.length; i += 1) {
 px = src[i].asArray();
 for (k = 0; k < 4; k += 1) {
 dta.data[(i * 4) + k] = px[k];
 }
 }
 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'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 costume %'costume'" type="reporter" category="looks"><comment 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 %'bitmap'" 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 costume %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 %'var' be %'value'" 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><block-definition s="$camera snap" type="reporter" category="sensing"><comment x="0" y="0" w="216" collapsed="false">takes a snapshot with the webcam and reports it as a new costume, or zero if the user cancels</comment><header></header><code></code><translations></translations><inputs></inputs><script><block s="doDeclareVariables"><list><l>test</l><l>pic</l></list></block><block s="doSetVar"><l>test</l><block s="evaluate"><block s="reportJSFunction"><list></list><l>var camDialog,
 result = false;

camDialog = new CamSnapshotDialogMorph(
 this.parentThatIsA(IDE_Morph),
 this,
 function () {result = null; },
 function (costume) {
 result = costume;
 this.close();
 }
);

camDialog.key = 'camera';
camDialog.popUp(this.world());
return function () {return result; };</l></block><list></list></block></block><block s="doWaitUntil"><block s="evaluate"><block s="reifyScript"><script><block s="doSetVar"><l>pic</l><block s="evaluate"><block var="test"/><list></list></block></block><block s="doReport"><block s="reportNot"><block s="reportEquals"><block var="pic"/><block s="reportBoolean"><l><bool>false</bool></l></block></block></block></block></script><list></list></block><list></list></block></block><block s="doReport"><block var="pic"/></block></script></block-definition></blocks> |