| title | summary | icon | publish |
|---|---|---|---|
brush |
Methods for painting images or patterns as fill when creating vector shapes. |
palette |
true |
Brushes are a powerful tool when drawing vector shapes on Badgeware. Instead of a solid flat colour, they can paint an image or a repeating pattern across the shapes you draw. In fact, color itself is a type of brush - anywhere that you might use color to set a pen, you can set that pen to a brush instead.
One use of brushes is to fill a shape with an image rather than with a flat colour. The image should be loaded in as a variable as usual, then passed into brush.image(). You can also pass in a transformation matrix as a mat3 to determine the size, translation and rotation of the image. This image will tile infinitely if its size is smaller than the shape it is filling.
brush.image(image, matrix)image- the image to use as the brush.matrix- amat3representing the transformation of the image.
A brush representing the brush, which then can be used to set an image's pen.
import math
skull = image.load("/system/assets/skull.png")
def update():
t = mat3().translate(-12, -12).rotate(badge.ticks / 100).translate(80, 60).scale(math.sin(badge.ticks / 1000) * 4)
imgbrush = brush.image(skull, t)
screen.pen = imgbrush
screen.shape(shape.circle(80, 60, 50))
run(update)A pattern brush works similarly to an image brush, but instead of a picture a pattern of lit pixels is used. You can pass in the foreground and background colours of the pattern. Patterns can either be picked from the built in range in Badgeware, or you can specify a custom pattern by inputting it yourself as a tuple. These patterns remain static and are pixel scaled, so they cannot have a transformation matrix applied to them like an image brush can.
brush.pattern(col1, col2, pattern)col1, col2- the foreground and backgroundcolors of the pattern.pattern- the pattern itself. Note that this can be an integer representing one of the built-in patterns, or a tuple of binary numbers representing a custom pattern.
A brush representing the brush, which then can be used to set an image's pen.
import math
def update():
custom_pattern = brush.pattern(color.rgb(255, 100, 100, 100), color.rgb(0, 0, 0, 0), (
0b00000000,
0b01111110,
0b01000010,
0b01011010,
0b01011010,
0b01000010,
0b01111110,
0b00000000))
screen.pen = custom_pattern
screen.shape(shape.circle(80 + math.cos(badge.ticks / 500) * 30, 60 + math.sin(badge.ticks / 1000) * 30, 30))
built_in_pattern = brush.pattern(color.rgb(100, 255, 100, 100), color.rgb(0, 0, 0, 0), 11)
screen.pen = built_in_pattern
screen.shape(shape.circle(80 + math.sin(badge.ticks / 250) * 60, 60 + math.cos(badge.ticks / 500) * 60, 30))
built_in_pattern = brush.pattern(color.rgb(100, 100, 255, 100), color.rgb(0, 0, 0, 0), 8)
screen.pen = built_in_pattern
screen.shape(shape.circle(80 + math.cos(badge.ticks / 250) * 60, 60 + math.sin(badge.ticks / 500) * 60, 30))
run(update)Note: The
0bat the beginning of the numbers in the custom pattern signify that the number is binary. The 1s and 0s following it are each row of the pattern.
| Name | Sample | Tiled |
|---|---|---|
| 0 | ![]() |
![]() |
| 1 | ![]() |
![]() |
| 2 | ![]() |
![]() |
| 3 | ![]() |
![]() |
| 4 | ![]() |
![]() |
| 5 | ![]() |
![]() |
| 6 | ![]() |
![]() |
| 7 | ![]() |
![]() |
| 8 | ![]() |
![]() |
| 9 | ![]() |
![]() |
| 10 | ![]() |
![]() |
| 11 | ![]() |
![]() |
| 12 | ![]() |
![]() |
| 13 | ![]() |
![]() |
| 14 | ![]() |
![]() |
| 15 | ![]() |
![]() |
| 16 | ![]() |
![]() |
| 17 | ![]() |
![]() |
| 18 | ![]() |
![]() |
| 19 | ![]() |
![]() |
| 20 | ![]() |
![]() |
| 21 | ![]() |
![]() |
| 22 | ![]() |
![]() |
| 23 | ![]() |
![]() |
| 24 | ![]() |
![]() |
| 25 | ![]() |
![]() |
| 26 | ![]() |
![]() |
| 27 | ![]() |
![]() |
| 28 | ![]() |
![]() |
| 29 | ![]() |
![]() |
| 30 | ![]() |
![]() |
| 31 | ![]() |
![]() |
| 32 | ![]() |
![]() |
| 33 | ![]() |
![]() |
| 34 | ![]() |
![]() |
| 35 | ![]() |
![]() |
| 36 | ![]() |
![]() |
| 37 | ![]() |
![]() |











































































