-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added graphic filter effects (matrix-kernel convolution tools) to the…
… pixels library
- Loading branch information
Showing
2 changed files
with
6 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<blocks app="Snap! 7, https://snap.berkeley.edu" version="2"><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>pt:$camera a imagem actual do vídeo
</translations><inputs></inputs><script><block s="doDeclareVariables"><list><l>callback</l><l>pic</l></list></block><block s="doSetVar"><l>callback</l><block s="reportApplyExtension"><l>mda_snap</l><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="callback"/><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><block-definition s="export costume %'costume'" type="command" category="looks"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true"><options>§_costumesMenu</options></input></inputs><script><block s="doSetVar"><l>costume</l><block s="reportIfElse"><block s="reportIsA"><block var="costume"/><l><option>costume</option></l></block><block var="costume"/><block s="reportFindFirst"><block s="reifyPredicate"><autolambda><block s="reportEquals"><block s="reportGetImageAttribute"><l><option>name</option></l><l></l></block><block var="costume"/></block></autolambda><list></list></block><block s="reportGet"><l><option>costumes</option></l></block></block></block></block><block s="doIf"><block s="reportIsA"><block var="costume"/><l><option>costume</option></l></block><script><block s="doApplyExtension"><l>cst_export(cst, name)</l><list><block var="costume"/><l></l></list></block></script></block></script></block-definition><block-definition s="set name of costume %'costume' to %'name'" type="command" category="looks"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true"><options>§_costumesMenu</options></input><input type="%s">thing</input></inputs><script><block s="doSetVar"><l>costume</l><block s="reportIfElse"><block s="reportIsA"><block var="costume"/><l><option>costume</option></l></block><block var="costume"/><block s="reportFindFirst"><block s="reifyPredicate"><autolambda><block s="reportEquals"><block s="reportGetImageAttribute"><l><option>name</option></l><l></l></block><block var="costume"/></block></autolambda><list></list></block><block s="reportGet"><l><option>costumes</option></l></block></block></block></block><block s="doIf"><block s="reportIsA"><block var="costume"/><l><option>costume</option></l></block><script><block s="doApplyExtension"><l>obj_name(obj, name)</l><list><block var="costume"/><block var="name"/></list></block></script></block></script></block-definition><block-definition s="export costume list %'costumes' base name %'name'" type="command" category="looks"><header></header><code></code><translations></translations><inputs><input type="%l"></input><input type="%s">frame</input></inputs><script><block s="doDeclareVariables"><list><l>count</l></list></block><block s="doSetVar"><l>count</l><block s="reportListAttribute"><l><option>length</option></l><block var="costumes"/></block></block><block s="doForEach"><l>item</l><block s="reportListAttribute"><l><option>reverse</option></l><block var="costumes"/></block><script><block s="doApplyExtension"><l>cst_export(cst, name)</l><list><block var="item"/><block s="reportJoinWords"><list><block var="name"/><l> (</l><block var="count"/><l>)</l></list></block></list></block><block s="doChangeVar"><l>count</l><l>-1</l></block><block s="doIf"><block s="reportEquals"><block s="reportModulus"><block var="count"/><l>10</l></block><l>0</l></block><script><block s="doWait"><l>1</l></block></script></block></script></block></script></block-definition></blocks> | ||
<blocks app="Snap! 9.0, https://snap.berkeley.edu" version="2"><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>pt:$camera a imagem actual do vídeo
</translations><inputs></inputs><script><block s="doDeclareVariables"><list><l>callback</l><l>pic</l></list></block><block s="doSetVar"><l>callback</l><block s="reportApplyExtension"><l>mda_snap</l><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="callback"/><list></list></block></block><block s="doReport"><block s="reportNot"><block s="reportVariadicEquals"><list><block var="pic"/><block s="reportBoolean"><l><bool>false</bool></l></block></list></block></block></block></script><list></list></block><list></list></block></block><block s="doReport"><block var="pic"/></block></script></block-definition><block-definition s="export costume %'costume'" type="command" category="looks"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true"><options>§_costumesMenu</options></input></inputs><script><block s="doSetVar"><l>costume</l><block s="reportIfElse"><block s="reportIsA"><block var="costume"/><l><option>costume</option></l></block><block var="costume"/><block s="reportFindFirst"><block s="reifyPredicate"><autolambda><block s="reportVariadicEquals"><list><block s="reportGetImageAttribute"><l><option>name</option></l><l></l></block><block var="costume"/></list></block></autolambda><list></list></block><block s="reportGet"><l><option>costumes</option></l></block></block></block></block><block s="doIf"><block s="reportIsA"><block var="costume"/><l><option>costume</option></l></block><script><block s="doApplyExtension"><l>cst_export(cst, name)</l><list><block var="costume"/><l></l></list></block></script><list></list></block></script></block-definition><block-definition s="set name of costume %'costume' to %'name'" type="command" category="looks"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true"><options>§_costumesMenu</options></input><input type="%s">thing</input></inputs><script><block s="doSetVar"><l>costume</l><block s="reportIfElse"><block s="reportIsA"><block var="costume"/><l><option>costume</option></l></block><block var="costume"/><block s="reportFindFirst"><block s="reifyPredicate"><autolambda><block s="reportVariadicEquals"><list><block s="reportGetImageAttribute"><l><option>name</option></l><l></l></block><block var="costume"/></list></block></autolambda><list></list></block><block s="reportGet"><l><option>costumes</option></l></block></block></block></block><block s="doIf"><block s="reportIsA"><block var="costume"/><l><option>costume</option></l></block><script><block s="doApplyExtension"><l>obj_name(obj, name)</l><list><block var="costume"/><block var="name"/></list></block></script><list></list></block></script></block-definition><block-definition s="export costume list %'costumes' base name %'name'" type="command" category="looks"><header></header><code></code><translations></translations><inputs><input type="%l"></input><input type="%s">frame</input></inputs><script><block s="doDeclareVariables"><list><l>count</l></list></block><block s="doSetVar"><l>count</l><block s="reportListAttribute"><l><option>length</option></l><block var="costumes"/></block></block><block s="doForEach"><l>item</l><block s="reportListAttribute"><l><option>reverse</option></l><block var="costumes"/></block><script><block s="doApplyExtension"><l>cst_export(cst, name)</l><list><block var="item"/><block s="reportJoinWords"><list><block var="name"/><l> (</l><block var="count"/><l>)</l></list></block></list></block><block s="doChangeVar"><l>count</l><l>-1</l></block><block s="doIf"><block s="reportVariadicEquals"><list><block s="reportModulus"><block var="count"/><l>10</l></block><l>0</l></list></block><script><block s="doWait"><l>1</l></block></script><list></list></block></script></block></script></block-definition><block-definition s="%'filter' filter on %'costume'" type="reporter" category="looks"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true">Blur<options>Blur
Sharpen
Outline
Emboss
Edge</options></input><input type="%s" readonly="true">current<options>§_costumesMenu</options></input></inputs><script><block s="doDeclareVariables"><list><l>kernel</l><l>pixels</l><l>channels</l><l>w</l><l>h</l></list></block><block s="doSetVar"><l>kernel</l><block s="reportIfElse"><block s="reportVariadicGreaterThan"><list><block s="reportListAttribute"><l><option>rank</option></l><block var="filter"/></block><l>1</l></list></block><block var="filter"/><custom-block s="filter %s"><block var="filter"/></custom-block></block></block><block s="doSetVar"><l>pixels</l><block s="reportGetImageAttribute"><l><option>pixels</option></l><block var="costume"/></block></block><block s="doIf"><block s="reportListContainsItem"><block s="reportNewList"><list><l>outline</l><l>emboss</l><l>edge</l></list></block><block var="filter"/></block><script><block s="doSetVar"><l>channels</l><l>3</l></block><block s="doSetVar"><l>pixels</l><block s="reportVariadicProduct"><list><block var="pixels"/><block s="reportNewList"><list><l>1</l><l>1</l><l>1</l></list></block></list></block><comment w="137" collapsed="true">remove alpha channel</comment></block></script><list><l><bool>true</bool></l><script><block s="doSetVar"><l>channels</l><l>4</l></block></script></list></block><block s="doSetVar"><l>w</l><block s="reportGetImageAttribute"><l><option>width</option></l><block var="costume"/></block></block><block s="doSetVar"><l>h</l><block s="reportGetImageAttribute"><l><option>height</option></l><block var="costume"/></block></block><block s="doReport"><block s="reportNewCostume"><block s="reportReshape"><custom-block s="convolve matrix %l * kernel %l"><block s="reportReshape"><block var="pixels"/><list><block var="h"/><block var="w"/><block var="channels"/></list></block><block var="kernel"/></custom-block><list><l></l><block var="channels"/></list></block><block var="w"/><block var="h"/></block></block></script></block-definition><block-definition s="filter %'name'" type="reporter" category="looks"><header></header><code></code><translations></translations><inputs><input type="%s" readonly="true">Blur<options>Blur
Sharpen
Outline
Emboss
Edge</options></input></inputs><script><block s="doIf"><block s="reportVariadicEquals"><list><block var="name"/><l>sharpen</l></list></block><script><block s="doReport"><custom-block s="kernel %br %n %n %n %br %n %n %n %br %n %n %n"><l>0</l><l>-1</l><l>0</l><l>-1</l><l>5</l><l>-1</l><l>0</l><l>-1</l><l>0</l></custom-block></block></script><list><block s="reportVariadicEquals"><list><block var="name"/><l>outline</l></list></block><script><block s="doReport"><custom-block s="kernel %br %n %n %n %br %n %n %n %br %n %n %n"><l>-1</l><l>-1</l><l>-1</l><l>-1</l><l>8</l><l>-1</l><l>-1</l><l>-1</l><l>-1</l></custom-block></block></script><block s="reportVariadicEquals"><list><block var="name"/><l>emboss</l></list></block><script><block s="doReport"><custom-block s="kernel %br %n %n %n %br %n %n %n %br %n %n %n"><l>-2</l><l>-1</l><l>0</l><l>-1</l><l>1</l><l>1</l><l>0</l><l>1</l><l>2</l></custom-block></block></script><block s="reportVariadicEquals"><list><block var="name"/><l>edge</l></list></block><script><block s="doReport"><custom-block s="kernel %br %n %n %n %br %n %n %n %br %n %n %n"><l>-1</l><l>0</l><l>1</l><l>-2</l><l>0</l><l>2</l><l>-1</l><l>0</l><l>1</l></custom-block></block></script></list></block><block s="doReport"><custom-block s="kernel %br %n %n %n %br %n %n %n %br %n %n %n"><l>0.0625</l><l>0.125</l><l>0.0625</l><l>0.125</l><l>0.25</l><l>0.125</l><l>0.0625</l><l>0.125</l><l>0.0625</l></custom-block></block></script></block-definition><block-definition s="kernel $nl %'a1' %'b1' %'c1' $nl %'a2' %'b2' %'c2' $nl %'a3' %'b3' %'c3'" type="reporter" category="lists"><header></header><code></code><translations></translations><inputs><input type="%n"></input><input type="%n"></input><input type="%n"></input><input type="%n"></input><input type="%n"></input><input type="%n"></input><input type="%n"></input><input type="%n"></input><input type="%n"></input></inputs><script><block s="doReport"><block s="reportNewList"><list><block s="reportNewList"><list><block var="a1"/><block var="b1"/><block var="c1"/></list></block><block s="reportNewList"><list><block var="a2"/><block var="b2"/><block var="c2"/></list></block><block s="reportNewList"><list><block var="a3"/><block var="b3"/><block var="c3"/></list></block></list></block></block></script></block-definition><block-definition s="convolve matrix %'matrix' * kernel %'kernel'" type="reporter" category="operators"><header></header><code></code><translations></translations><inputs><input type="%l"></input><input type="%l"></input></inputs><script><block s="doDeclareVariables"><list><l>channels</l><l>every coordinate</l><l>padding</l></list></block><block s="doSetVar"><l>padding</l><block s="reportQuotient"><block s="reportDifference"><block s="reportListItem"><block s="reportNewList"><list><l>1</l><l>2</l></list></block><block s="reportListAttribute"><l><option>dimensions</option></l><block var="kernel"/></block></block><l>1</l></block><l>2</l></block><comment w="119" collapsed="false">assume odd dimensions, typically 3x3 or 5x5</comment></block><block s="doSetVar"><l>channels</l><block s="reportListItem"><l>3</l><block s="reportListAttribute"><l><option>dimensions</option></l><block var="matrix"/></block></block></block><block s="doIf"><block s="reportVariadicAnd"><list><block s="reportVariadicGreaterThan"><list><block var="channels"/><l>0</l></list></block><block s="reportVariadicLessThan"><list><block s="reportListAttribute"><l><option>dimensions</option></l><block var="kernel"/></block><l>3</l></list></block></list></block><script><block s="doSetVar"><l>kernel</l><block s="reportReshape"><custom-block s="stretch %l by %n"><block s="reportListAttribute"><l><option>flatten</option></l><block var="kernel"/></block><block var="channels"/></custom-block><block s="reportConcatenatedLists"><list><block s="reportListAttribute"><l><option>dimensions</option></l><block var="kernel"/></block><block s="reportNewList"><list><block var="channels"/></list></block></list></block></block></block></script><list></list><comment w="90" collapsed="false">reshape the kernel to match the input matrix's channels, if any</comment></block><block s="doSetVar"><l>every coordinate</l><block s="reportCrossproduct"><block s="reportNumbers"><l>1</l><block s="reportListItem"><block s="reportNewList"><list><l>1</l><l>2</l></list></block><block s="reportListAttribute"><l><option>dimensions</option></l><block var="matrix"/></block></block></block></block></block><block s="doReport"><block s="reportReshape"><block s="reportVariadicSum"><block s="reportListAttribute"><l><option>columns</option></l><block s="reportVariadicSum"><block s="reportListAttribute"><l><option>columns</option></l><block s="reportVariadicProduct"><list><block s="reportListItem"><block s="reportNumbers"><block s="reportDifference"><block var="every coordinate"/><block var="padding"/></block><block s="reportVariadicSum"><list><block var="every coordinate"/><block var="padding"/></list></block></block><block var="matrix"/></block><block var="kernel"/></list></block></block></block></block></block><block s="reportListAttribute"><l><option>dimensions</option></l><block var="matrix"/></block><comment w="80" collapsed="false">for every padded pixel create a partial copy of the input, item-multiply it with the kernel and take its overall sum (∑)</comment></block></block></script></block-definition><block-definition s="stretch %'data' by %'factor'" type="reporter" category="lists"><header></header><code></code><translations></translations><inputs><input type="%l"></input><input type="%n"></input></inputs><script><block s="doReport"><block s="reportListItem"><block s="reportMonadic"><l><option>ceiling</option></l><block s="reportQuotient"><block s="reportNumbers"><l>1</l><block s="reportVariadicProduct"><list><block s="reportListAttribute"><l><option>length</option></l><block var="data"/></block><block var="factor"/></list></block></block><block var="factor"/></block></block><block var="data"/></block></block></script></block-definition></blocks> |