new "Pixels" library for MediaComp

upd4.1
Jens Mönig 2017-09-28 10:57:13 +02:00
rodzic 2cbc839005
commit 51998503a3
3 zmienionych plików z 4 dodań i 0 usunięć

Wyświetl plik

@ -3671,6 +3671,7 @@ Fixes:
* Blocks: made "import script" undoable
* Objects: make sure inheritance hierarchies are consistently made temporary
* new "Animation" library
* new "Pixels" library for MediaComp
v4.1 Features:
@ -3707,6 +3708,7 @@ v4.1 Features:
* "Make a block" button in every category
* experimental "download script" feature
* new "Animation" library
* new "Pixels" library for MediaComp
Fixes:
* changed keyboard shortcut indicator for “find blocks” to “^”

Wyświetl plik

@ -13,3 +13,4 @@ multiline.xml Allow multi-line text input to a block In general, text inputs all
Eisenbergification.xml Provide getters and setters for all GUI-controlled global settings Eisenberg's Law: Anything that can be done from the GUI should be doable from the programming language, and vice versa.
bignumbers.xml Infinite precision integers, exact rationals, complex The full Scheme numeric tower. "USE BIGNUMS <True>" to enable.
animation_module.xml Animation glide, grow and rotate using easing functions.
pixel_module.xml Pixels manipulate costumes pixel-wise.

Wyświetl plik

@ -0,0 +1 @@
<blocks app="Snap! 4.1, http://snap.berkeley.edu" version="1"><block-definition s="pixels in %&apos;costume&apos;" type="reporter" category="sensing"><comment x="0" y="0" 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><inputs><input type="%obj"></input></inputs><script><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><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="looks"><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><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><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><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><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>