- This article is about the pen feature. For pen blocks, see Pen Blocks.
Lines, dots, rectangles, and circles are the easiest shapes to draw, but with enough scripting, any shape can be created.
Blocks Related to Pen
- Main article: Pen Blocks
- Clear — Clears all pen marks on the screen
- Pen Down — Turns the pen feature on inside a sprite; the sprite will pen on the screen wherever it moves until the pen is turned off
- Pen Up — Turns the pen feature off, stopping a sprite from penning
- Set Pen Color to  — Sets the color of the pen to a color chosen by the programmer
- Change Pen Color by () — Changes the pen color by a certain value
- Set Pen Color to () — Sets the color of the pen to a color chosen by the programmer using a number system
- Change Pen Shade by () — Changes the shade of the color by a chosen value
- Set Pen Shade to () — Sets the shade of the color to a chosen value
- Change Pen Size by () — Changes the size of the pen by a chosen number
- Set Pen Size to () — Sets the size of the pen to a chosen number
- Stamp — Draws a copy of the Sprite on the Stage
Flash Player Glitches
The Flash Player appears to set a maximum pen size. This is due to the Flash Player using one byte of data to store the pen size. There are 256 possible outcomes of one byte (28 values encoded in 8 binary bits), so the Flash Player most likely uses the 256 possible outcomes to each stand for a pen size from 0-255.
The Flash Player also has a bug where the pen size "1" does not paint the entire pixel. If the pen size is set to 1 and used in Scratch to paint every pixel, a solid region will be formed. However, with the Flash Player, a translucent region will be formed as only part of each pixel will be colored. To avoid this, set the pen size to "2" if you want it to be one pixel on the Flash Player.
However, this glitch can be helpful if one wants to draw transparent regions on the flash player. It would take a long time to draw the transparent figure pixel by pixel even with turbo speed, so a sprite using the ghost Graphic Effect would be more effective.
Also, when Flash Player is drawing with the pen using medium or low quality, very low pen sizes are not drawn at all. To change the quality in the flash player:
- Right-click or control-click (Mac) the project
- Click on Quality
- Choose desired quality
The pen blocks are often used to:
- Make Snake style games
- Make a trail behind a sprite
- Drawing objects in one sprite, one script projects
- Drawing patterns
- Creating graphs
- Program graphics editors
- 3D projects
- Text Rendering
The formula for ARGB (aka RGBA) is similar to that of RGB (red, green, and blue), but it has an additional value, Alpha (A) for opacity. Alpha is identified by a number 1-255, where 1 is completely transparent and 255 is opaque. The formula for RGB (without Alpha) is:
set pen color to ((((R) * (65536)) + ((G) * (256))) + (B)) // Be sure to use the pen color block with the color input (like the one below), or the colors will not function properly. set pen color to [#0000FF]
And the formula for ARGB is:
set pen color to ((((A) * (16777216)) + ((R) * (65536))) + (((G) * (256)) + (B)))
Warning: Make sure the A, R, G, and B values are whole numbers (rounded) so they don't contribute to other colors' values. To ensure that this does not happen, it is recommended that you use the following code:
set pen color to ((((round (A)) * (16777216)) + ((round (R)) * (65536))) + (((round(G)) * (256)) + (round (B))))
Use of "run without screen refresh" custom block
Run without screen refresh is a custom block operation that is used to speed up actions by refreshing the screen only after the operation has finished. When you create a custom block, select "run without screen refresh" in the Options. A script that could use the custom block to draw a picture may look like this:
define draw // Here's our block! set [repeater v] to (0) // Our variable keeps track of which item to pick on the color list set pen size to (2) // Set the size to 2 to avoid a Flash Player glitch go to x (-240) y (180) // Starting pos repeat (360) // Repeat y repeat (480) // Repeat x change [repeater v] by (1) // Change our variable by 1 set pen color to (item (repeater) of [list v]) // Set the pen color to what it's meant to be from the list pen down // Pen down pen up // Pen up change x by (1) // Change x by 1 end set x to (-240) // Back at the far left of the screen change y by (-1) // Change our y by -1 end
or as a variable:
define draw // Here's our block! set [repeater v] to (0) // Our variable keeps track of which item to pick on the color list set pen size to (2) // Set the size to 2 to avoid a Flash Player glitch go to x (-240) y (180) // Starting pos repeat (360) // Repeat y repeat (480) // Repeat x change [repeater v] by (3) // Change our variable by 3 (length of 200, the max color) set [temporaryvar v] to  // A temporary variable creating the color from the variable set [temporaryvar v] to (letter ((repeater) - (2)) of (variable) set [temporaryvar v] to (join (temporaryvar) (letter ((repeater) - (1)) of (variable)) set [temporaryvar v] to (join (temporaryvar) (letter (repeater) of (variable)) set pen color to () // Set the pen color to what it's meant to be from the list pen down // Pen down pen up // Pen up change x by (1) // Change x by 1 end set x to (-240) // Back at the far left of the screen change y by (-1) // Change our y by -1 end
Of course you are going to have to make a list or variable to contain all the colors, and it's going to have to be 172800 colors long. However, lower resolution images can be created by tweaking the scripts, and it will require less items for the list. And a few scripts may create an image editor that can save the image you have drawn to a list.