turtlestitch/libraries/tools.xml

1 wiersz
16 KiB
XML
Czysty Zwykły widok Historia

<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="empty? %&apos;data&apos;" type="predicate" category="lists"><header></header><code></code><translations>de:ist _ leer?&#xD;ca:_ buida?&#xD;es:_ vacía?&#xD;fr:_ vide?&#xD;</translations><inputs><input type="%l"></input></inputs><script><block s="doReport"><block s="reportEquals"><block var="data"/><block s="reportNewList"><list></list></block></block></block></script></block-definition><block-definition s="keep items such that %&apos;pred&apos; from %&apos;data&apos;" type="reporter" category="lists"><header></header><code></code><translations>de:behalte Elemente, die _ aus _&#xD;ca:manté els elements on _ de _&#xD;es:mantener los elementos donde _ de _&#xD;fr:garder les items tels que _ de _&#xD;</translations><inputs><input type="%predRing"></input><input type="%l"></input></inputs><script><block s="doIf"><custom-block s="empty? %l"><block var="data"/></custom-block><script><block s="doReport"><block s="reportNewList"><list></list></block></block></script></block><block s="doIfElse"><block s="evaluate"><block var="pred"/><list><block s="reportListItem"><l>1</l><block var="data"/></block></list></block><script><block s="doReport"><block s="reportCONS"><block s="reportListItem"><l>1</l><block var="data"/></block><custom-block s="keep items such that %predRing from %l"><block var="pred"/><block s="reportCDR"><block var="data"/></block></custom-block></block></block></script><script><block s="doReport"><custom-block s="keep items such that %predRing from %l"><block var="pred"/><block s="reportCDR"><block var="data"/></block></custom-block></block></script></block></script></block-definition><block