new "text costumes" library for generating costumes from letters or words of text

pull/89/head
jmoenig 2019-03-11 09:49:28 +01:00
rodzic 5246d62144
commit ecdfdf7538
3 zmienionych plików z 4 dodań i 0 usunięć

Wyświetl plik

@ -18,6 +18,7 @@
* multi-line and monospaced "code" input slots for custom blocks
* new "string" library, thanks, Brian
* added "neg" selector to monadic function reporter in "Operators" category
* new "text costumes" library for generating costumes from letters or words of text
* enhanced support for embedding Snap in other website, thanks, Bernat!
* export sounds
* Notable Changes:
@ -50,6 +51,7 @@
### 2019-03-11
* added note / hz conversion blocks to audioComp library
* ported multiline library to new (custom input slot) format
* new "text costumes" library for generating costumes from letters or words of text
### 2019-03-10
* Objects, Blocks, Threads: added microphone note and pitch detection

Wyświetl plik

@ -7,6 +7,7 @@ httpBlocks.xml Web services access (https) An extended version of the HTTP:// bl
word-sentence.xml Words, sentences One of the big ideas in Logo that they left out of Scratch is thinking of text as structured into words and sentences, rather than just a string of characters. This library (along with the JOIN WORDS block in the Tools library) brings back that idea.
cases.xml Multi-branched conditional (switch) Like "switch" in C-like languages or "cond" in Lisp. Thanks to Nathan Dinsmore for inventing the idea of a separate block for each branch!
leap-library.xml LEAP Motion controller Report hand positions from LEAP Motion controller (leapmotion.com).
textCostumes_module.xml Text Costumes Generate costumes from letters or words of text.
setrgb.xml Set RGB or HSV pen color Set or report pen color as RGB (red, green, blue) or HSV (hue, saturation, value).
try-catch.xml Catch errors in a script Run a script; if an error happens, instead of stopping the script with a red halo, run another script to handle the error. Also includes a block to cause an error with a message given as input. Also includes a block to create a script variable and give it a value.
multiline.xml Allow multi-line text input to a block In general, text inputs allow only a single line. The MULTILINE block accepts multi-line text input and can be used in text input slots of other blocks.

Wyświetl plik

@ -0,0 +1 @@
<blocks app="Snap! 5.0, http://snap.berkeley.edu" version="1"><block-definition s="label %&apos;text&apos; of size %&apos;size&apos;" type="command" category="pen"><comment x="0" y="0" w="90" collapsed="false">LABEL will stamp text on the stage at the given font size. The direction of the text is the direction the sprite is facing, and color will match the pen color.</comment><header></header><code></code><translations>de:drucke _ in Größe _&#xD;ca:etiqueta _ de mida _&#xD;es:etiqueta _ de tamaño _&#xD;fr:étiquette _ d&apos;une taille de _&#xD;</translations><inputs><input type="%txt">Hello!</input><input type="%n">12</input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>text</l><l>size</l><l>process</l></list><l>var stage = this.parentThatIsA(StageMorph);&#xD;&#xD;if (this == stage) {&#xD; throw new Error(&#xD; &apos;LABEL cannot be used from the stage because the stage does not have a postion.\n&apos;&#xD; + &apos;Use LABEL from a sprite to draw text.&apos;);&#xD;}&#xD;&#xD;if (typeof text !== &apos;string&apos; &amp;&amp; typeof text !== &apos;number&apos;) {&#xD; throw new Error(&apos;LABEL can only draw text or numbers, not a &apos; + process.reportTypeOf(text)); &#xD;}&#xD;&#xD;var context = stage.penTrails().getContext(&apos;2d&apos;),&#xD; rotation = radians(this.direction() - 90),&#xD; trans = new Point(&#xD; this.center().x - stage.left(),&#xD; this.center().y - stage.top()&#xD; ),&#xD; isWarped = this.Warped,&#xD; len,&#xD; pos;&#xD;&#xD;if (isWarped) {endWarp(); }&#xD;context.save();&#xD;context.font = size + &apos;px monospace&apos;;&#xD;context.textAlign = &apos;left&apos;;&#xD;context.textBaseline = &apos;alphabetic&apos;;&#xD;context.fillStyle = this.color.toString();&#xD;len = context.measureText(text).width;&#xD;trans = trans.multiplyBy(1 / stage.scale);&#xD;context.translate(trans.x, trans.y);&#xD;context.rotate(rotation);&#xD;context.fillText(text, 0, 0);&#xD;context.translate(-trans.x, -trans.y);&#xD;context.restore();&#xD;pos = new Point(&#xD; len * Math.sin(radians(this.direction())),&#xD; len * Math.cos(radians(this.direction())));&#xD;pos = pos.add(new Point(this.xPosition(), this.yPosition()));&#xD;this.gotoXY(pos.x, pos.y, false);&#xD;this.changed();&#xD;if (isWarped) {this.startWarp(); }&#xD;stage.changed();&#xD;</l></block><list><block var="text"/><block var="size"/></list></block></script></block-definition><block-definition s="costume from text %&apos;text&apos; size %&apos;size&apos;" type="reporter" category="looks"><header></header><code></code><translations>de:Kostüm aus Text _ Größe _&#xD;</translations><inputs><input type="%s">A</input><input type="%n">72</input></inputs><script><block s="doDeclareVariables"><list><l>costume</l><l>x</l><l>y</l><l>dir</l><l>cst</l><l>trails</l></list></block><block s="doSetVar"><l>x</l><block s="xPosition"></block></block><block s="doSetVar"><l>y</l><block s="yPosition"></block></block><block s="doSetVar"><l>dir</l><block s="direction"></block></block><block s="doSetVar"><l>cst</l><block s="getCostumeIdx"></block></block><block s="up"></block><block s="gotoXY"><l>0</l><l>0</l></block><block s="setHeading"><l>90</l></block><block s="doSwitchToCostume"><l><option>Turtle</option></l></block><block s="doSetVar"><l>trails</l><block s="reportPenTrailsAsCostume"></block></block><block s="clear"></block><custom-block s="label %txt of size %n"><block var="text"/><block var="size"/></custom-block><block s="doSetVar"><l>costume</l><block s="reportPenTrailsAsCostume"></block></block><block s="clear"></block><block s="doRun"><block s="reportJSFunction"><list><l>costume</l><l>name</l></list><l>costume.name = name;</l></block><list><block var="costume"/><block var="text"/></list></block><block s="gotoXY"><l>0</l><l>0</l></block><block s="doSwitchToCostume"><block var="trails"/></block><block s="doStamp"></block><block s="doSwitchToCostume"><block var="cst"/></block><block s="gotoXY"><block var="x"/><block var="y"/></block><block s="setHeading"><block var="dir"/></block><block s="doReport"><block var="costume"/></block></script></block-definition></blocks>