Costume from text (but better)

Hi there! This is a block that you can use to make costumes with text and it has great quality and many more features.


It's fast and reverts things as before

Doesn't take a lot of time. Prints the text and returns it. It also reverts things like before so you don't notice any changes. Just use very carefully to not interrupt the process of the block.

Supports almost all contexts

This block can manage data that the block of the library does not. Using invalid data will cause an error, and data that cannot be handled by the block correctly will be replaced with default values.

Gives the best quality and text with no cuts

Will depend of the size of the stage, but this block will try to clamp text to the stage if it's too big to prevent cuts. To use the highest quality use .

Source

Copy and Import:

<blocks app="Snap! 7, https://snap.berkeley.edu" version="2"><block-definition s="costume from text %&apos;text&apos; quality %&apos;quality&apos;" type="reporter" category="looks"><comment w="147" collapsed="false">Reports a costume with the text printed. Supports all contexts.&#xD;&#xD;TIP: To use the highest quality, leave the quality number blank.</comment><header></header><code></code><translations></translations><inputs><input type="%s">Hello!</input><input type="%n">11</input></inputs><script><block s="doIf"><block s="reportEquals"><block s="reportGet"><l><option>self</option></l></block><block s="reportGet"><l><option>stage</option></l></block></block><script><block s="doDeclareVariables"><list><l>sprites</l></list></block><block s="doSetVar"><l>sprites</l><block s="reportGet"><l><option>other sprites</option></l></block></block><block s="doIfElse"><block s="reportEquals"><block s="reportListAttribute"><l><option>length</option></l><block var="sprites"/></block><l>0</l></block><script><block s="doApplyExtension"><l>err_error(msg)</l><list><l>expecting at least one sprite</l></list></block></script><script><block s="doReport"><block s="reportAskFor"><block s="reportListItem"><l><option>any</option></l><block var="sprites"/></block><block s="reifyReporter"><autolambda><custom-block s="costume from text %s quality %n"><block var="text"/><block var="quality"/></custom-block></autolambda><list></list></block><list></list></block></block></script></block></script><comment w="99" collapsed="false">If called on stage, will ask anothe sprite for the costume.</comment></block><block s="doIf"><block s="reportNot"><block s="reportOr"><block s="reportIsA"><block var="text"/><l><option>text</option></l></block><block s="reportIsA"><block var="text"/><l><option>number</option></l></block></block></block><script><block s="doApplyExtension"><l>err_error(msg)</l><list><l>can only get a costume of text or numbers, not a object</l></list></block></script><comment w="88" collapsed="false">Verifies if it&apos;s a text or numbers.</comment></block><block s="doDeclareVariables"><list><l>data</l><l>result</l></list></block><block s="doSetVar"><l>data</l><block s="reportNewList"><list><block s="xPosition"></block><block s="yPosition"></block><block s="direction"></block><block s="reportGet"><l><option>costume</option></l></block><block s="getEffect"><l><option>color</option></l></block><block s="getEffect"><l><option>saturation</option></l></block><block s="getEffect"><l><option>brightness</option></l></block><block s="getEffect"><l><option>ghost</option></l></block><block s="getEffect"><l><option>fisheye</option></l></block><block s="getEffect"><l><option>whirl</option></l></block><block s="getEffect"><l><option>pixelate</option></l></block><block s="getEffect"><l><option>mosaic</option></l></block><block s="getEffect"><l><option>negative</option></l></block><block s="getScale"></block><block s="getPenDown"></block><block s="getPenAttribute"><l><option>r-g-b-a</option></l></block><block s="reportPenTrailsAsCostume"></block><block var="text"/></list></block></block><block s="doIf"><block s="reportLessThan"><block s="reportStringSize"><block var="text"/></block><l>5</l></block><script><block s="doWarp"><script><block s="doRepeat"><block s="reportDifference"><l>5</l><block s="reportStringSize"><block var="text"/></block></block><script><block s="doSetVar"><l>text</l><block s="reportJoinWords"><list><block var="text"/><l> </l></list></block></block></script></block></script></block></script><comment w="130" collapsed="false">Put space after the text to give more height to the text.</comment></block><block s="doIf"><block s="reportNot"><block s="reportIsA"><block var="quality"/><l><option>number</option></l></block></block><script><block s="doSetVar"><l>quality</l><l>11</l></block></script><comment w="179.03515625" collapsed="false">If quality is not a number, then uses the default one.</comment></block><block s="doIf"><block s="reportOr"><block s="reportGreaterThan"><block var="quality"/><l>10000</l></block><block s="reportLessThanOrEquals"><block var="quality"/><l>0</l></block></block><script><block s="doSetVar"><l>quality</l><l>10000</l></block></script><comment w="121" collapsed="false">10000 is the highest quality possible on Snap!</comment></block><block s="setPenColorDimension"><l><option>r-g-b(-a)</option></l><block s="reportNewList"><list><l>80</l><l>80</l><l>80</l><l>255</l></list></block></block><block s="gotoXY"><block s="reportAttributeOf"><l><option>left</option></l><l>Stage</l></block><l>0</l></block><block s="setHeading"><l>90</l></block><block s="clearEffects"></block><block s="setScale"><l>100</l></block><block s="up"></block><block s="clear"><comment w="191" collapsed="false">Put the sprite information to a default one.</comment></block><block s="write"><block var="text"/><block var="quality"/></block><block s="doIf"><block s="reportGreaterThan"><block s="xPosition"></block><block s="reportAttributeOf"><l><option>right</option></l><l>Stage</l></block></block><script><block s="doDeclareVariables"><list><l>x delta</l><l>x pos</l></list></block><block s="doSetVar"><l>x delta</l><block s="reportProduct"><block s="xPosition"></block><l>-1</l></block></block><block s="doSetVar"><l>x pos</l><block s="reportDifference"><block s="xPosition"></block><block s="reportAttributeOf"><l><option>right</option></l><l>Stage</l></block></block></block><block s="write"><block var="text"/><l>1</l></block><block s="doChangeVar"><l>x delta</l><block s="xPosition"></block></block><block s="gotoXY"><block s="reportAttributeOf"><l><option>left</option></l><l>Stage</l></block><l>0</l></block><block s="clear"></block><block s="write"><block var="text"/><block s="reportDifference"><block var="quality"/><block s="reportQuotient"><block var="x pos"/><block var="x delta"/></block></block></block></script><comment w="177" collapsed="false">If the text is too big to put on the stage, it will clamp it to get the full text.</comment></block><block s="doSetVar"><l>result</l><block s="reportPenTrailsAsCostume"></block></block><block s="doApplyExtension"><l>obj_name(obj, name)</l><list><block var="result"/><block s="reportJoinWords"><list><block s="reportListItem"><l>18</l><block var="data"/></block><l></l></list></block></list><comment w="131" collapsed="false">Put the name of the costume as the text itself.</comment></block><block s="clear"></block><block s="gotoXY"><block s="reportListItem"><l>1</l><block var="data"/></block><block s="reportListItem"><l>2</l><block var="data"/></block></block><block s="doSwitchToCostume"><block s="reportListItem"><l>17</l><block var="data"/></block></block><block s="doStamp"><comment w="167.9873046875" collapsed="false">Reverts pen trails, but loses quality.</comment></block><block s="setPenColorDimension"><l><option>r-g-b(-a)</option></l><block s="reportListItem"><l>16</l><block var="data"/></block></block><block s="setEffect"><l><option>brightness</option></l><block s="reportListItem"><l>7</l><block var="data"/></block></block><block s="setEffect"><l><option>saturation</option></l><block s="reportListItem"><l>6</l><block var="data"/></block></block><block s="setEffect"><l><option>negative</option></l><block s="reportListItem"><l>13</l><block var="data"/></block></block><block s="setEffect"><l><option>pixelate</option></l><block s="reportListItem"><l>11</l><block var="data"/></block></block><block s="setEffect"><l><option>mosaic</option></l><block s="reportListItem"><l>12</l><block var="data"/></block></block><block s="setEffect"><l><option>fisheye</option></l><block s="reportListItem"><l>9</l><block var="data"/></block></block><block s="setEffect"><l><option>whirl</option></l><block s="reportListItem"><l>10</l><block var="data"/></block></block><block s="setEffect"><l><option>ghost</option></l><block s="reportListItem"><l>8</l><block var="data"/></block></block><block s="setEffect"><l><option>color</option></l><block s="reportListItem"><l>5</l><block var="data"/></block></block><block s="doSwitchToCostume"><block s="reportListItem"><l>4</l><block var="data"/></block></block><block s="setHeading"><block s="reportListItem"><l>3</l><block var="data"/></block></block><block s="setScale"><block s="reportListItem"><l>14</l><block var="data"/></block></block><block s="doIf"><block s="reportListItem"><l>15</l><block var="data"/></block><script><block s="down"></block></script></block><block s="doReport"><block var="result"/><comment w="131" collapsed="false">Reverts the sprite as before and reports the costume.</comment></block></script></block-definition></blocks>

(C) 2022 ScratchModification

This is annoying to work with, could you please just make a project with the blocks and share it?
Also, it's misleading to call the text size "quality"... why not just say "size"?
Also, no offense, but this seems pretty much identical to the library block in every aspect other than code and behaviors.

Don't you know how to import a block?

This doesn't print anything, just report a costume.

I think I'm going to make comparisons between that two blocks.

Well, you're telling people to paste it into a new file on their computer, save that as an xml file, then load it into snap. It's much much easier to share a project so people can just click a link to immediately start playing with it.

I know. Changing that input does the same thing in printing and text costumes; it affects the size of the text. Why make a distinction between the two? It feels unnecessary.

I do, it's just really annoying to have to make your own file or use the console or whatever, and most people probably wouldn't think of that. At least include instructions.

You don't have to convert it as an XML file. Just go to Notepad, paste it and save it as a TXT file. Then go to Snap! and import it.

Oh, by the way, you can't really do that on a Chromebook as far as I know.

But it's an xml file, not a txt. But it's still easier to click a link.

So, is there another solution for that?

Just make a project, share it, and give the link! It's quite easy.

I've made the XML into a project: Snap! 7.0.6 - Build Your Own Blocks

You can, just use the Text program.

This is a comparison between the Snap! library block () and my custom block (untitled script pic (18)). No offense is intended. For @helicoptur


Feature
My custom block
Snap! library block
Reports costume
:heavy_check_mark:
:heavy_check_mark:
Adjusts the size of the text
:heavy_check_mark:
:x:
Fast process
:heavy_check_mark:
:heavy_check_mark:
Reverts position
:heavy_check_mark:
:heavy_check_mark:
Reverts orientation
:heavy_check_mark:
:heavy_check_mark:
Reverts costume
:heavy_check_mark:
:heavy_check_mark:
Reverts size
:heavy_check_mark:
:x:
Reverts effects
:heavy_check_mark:
:x:
Reverts pen state
:heavy_check_mark:
:heavy_check_mark:
Reverts pen RGBA
:heavy_check_mark:
:x:
Reverts pen trails
:heavy_check_mark:
:heavy_check_mark:
Can report on stage
:heavy_check_mark:
:x:
Primitive block can't bug
:heavy_check_mark:
:x:
Can detect interruptions
:x:
:x:
Pen trails don't lose quality
:x:
:x:

As can you see, this is the best option​:arrow_up: . If you have any question reply here.


(C) 2022 ScratchModification

I think quality is the best word to describe what I want. Less "size" means less pixels and that means less quality.

Okay, but they're the same thing, and "quality" could be confusing.

Why would you change these in the block??

What does this mean?

Since the issue came up in another thread, let me point out that this isn't a very constructive forum conversation. Helicoptur, "annoying" was the very first thing you said about the project. That's what started the hostile tone of the conversation following it. Scratchmodification, you replied with an ad hominem attack.

Both of you can do better than this.


As to the actual project, I was surprised to find that neither this nor the library version saves PEN DOWN?, which you actually do change, or should anyway, to avoid drawing a line from the sprite's original position to the left edge and then underlining the text. I'll fix that in the library version; thanks for getting me to notice it!

Or this script can't be easier?
untitled script pic(2)

But this have a downside with pen projects :confused:

Good spot! I think I'm gonna update it to save untitled script pic (19) as well.

Edit: Updated it, please use the newest version.

The library only saves and reverts position, direction, costume and pen trails. Will mess up if you use sprite effects or if you change pen RGBA.

Do this with the library block:


With my custom block:

It does not bug when i use reporter. I don't know why, but I think it's a JS bug.