Skip to content

Latest commit

 

History

History
117 lines (99 loc) · 6.8 KB

File metadata and controls

117 lines (99 loc) · 6.8 KB
title summary icon publish
brush
Methods for painting images or patterns as fill when creating vector shapes.
palette
true

Introduction

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.

Image brushes

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.

Usage

  • brush.image(image, matrix)
    • image - the image to use as the brush.
    • matrix - a mat3 representing the transformation of the image.

Returns

A brush representing the brush, which then can be used to set an image's pen.

Example

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)

Pattern brushes

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.

Usage

  • brush.pattern(col1, col2, pattern)
    • col1, col2 - the foreground and background colors 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.

Returns

A brush representing the brush, which then can be used to set an image's pen.

Example

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 0b at 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 Pattern 0 Pattern 0 Tiled
1 Pattern 1 Pattern 1 Tiled
2 Pattern 2 Pattern 2 Tiled
3 Pattern 3 Pattern 3 Tiled
4 Pattern 4 Pattern 4 Tiled
5 Pattern 5 Pattern 5 Tiled
6 Pattern 6 Pattern 6 Tiled
7 Pattern 7 Pattern 7 Tiled
8 Pattern 8 Pattern 8 Tiled
9 Pattern 9 Pattern 9 Tiled
10 Pattern 10 Pattern 10 Tiled
11 Pattern 11 Pattern 11 Tiled
12 Pattern 12 Pattern 12 Tiled
13 Pattern 13 Pattern 13 Tiled
14 Pattern 14 Pattern 14 Tiled
15 Pattern 15 Pattern 15 Tiled
16 Pattern 16 Pattern 16 Tiled
17 Pattern 17 Pattern 17 Tiled
18 Pattern 18 Pattern 18 Tiled
19 Pattern 19 Pattern 19 Tiled
20 Pattern 20 Pattern 20 Tiled
21 Pattern 21 Pattern 21 Tiled
22 Pattern 22 Pattern 22 Tiled
23 Pattern 23 Pattern 23 Tiled
24 Pattern 24 Pattern 24 Tiled
25 Pattern 25 Pattern 25 Tiled
26 Pattern 26 Pattern 26 Tiled
27 Pattern 27 Pattern 27 Tiled
28 Pattern 28 Pattern 28 Tiled
29 Pattern 29 Pattern 29 Tiled
30 Pattern 30 Pattern 30 Tiled
31 Pattern 31 Pattern 31 Tiled
32 Pattern 32 Pattern 32 Tiled
33 Pattern 33 Pattern 33 Tiled
34 Pattern 34 Pattern 34 Tiled
35 Pattern 35 Pattern 35 Tiled
36 Pattern 36 Pattern 36 Tiled
37 Pattern 37 Pattern 37 Tiled