|
1 | | -The drawing functions are used to draw shapes and lines on the screen unlike in Scratch where you have to move a pen. They can be used to create graphics, animations, and more. It also lets you stamp the sprite onto the stage. Here is a list of all the drawing functions in Crust: |
2 | | - |
3 | | -- `set_color(r, g, b)`: Sets the drawing color to the specified RGB values. The values are in the range of 0 to 255. |
4 | | -- `change_r(increment)`: Changes the red component of the drawing color by the specified increment. The increment can be positive or negative. |
5 | | -- `change_g(increment)`: Changes the green component of the drawing color by the specified increment. The increment can be positive or negative. |
6 | | -- `change_b(increment)`: Changes the blue component of the drawing color by the specified increment. The increment can be positive or negative. |
7 | | -- `line(x1, y1, x2, y2, thickness)`: Draws a line from the point `(x1, y1)` to the point `(x2, y2)` with the specified thickness. |
8 | | -- `rect(x1, y1, x2, y2)`: Draws a rectangle with the top-left corner at `(x1, y1)` and the bottom-right corner at `(x2, y2)`. The rectangle is filled with the current drawing color. |
9 | | -- `hrect(x1, y1, x2, y2, thickness)`: Draws a hollow rectangle with the top-left corner at `(x1, y1)` and the bottom-right corner at `(x2, y2)` with the specified thickness. The rectangle is outlined with the current drawing color. |
10 | | -- `circle(x, y, radius)`: Draws a filled circle with the center at `(x, y)` and the specified radius. The circle is filled with the current drawing color. |
11 | | -- `hcircle(x, y, radius, thickness)`: Draws a hollow circle with the center at `(x, y)` and the specified radius with the specified thickness. The circle is outlined with the current drawing color. |
12 | | -- `ellipse(x, y, width, height)`: Draws a filled ellipse with the center at `(x, y)` and the specified width and height. The ellipse is filled with the current drawing color. |
13 | | -- `ellipse(x, y, width, height, rotation)`: Draws a filled ellipse with the center at `(x, y)`, the specified width and height, and the specified rotation in degrees. The ellipse is filled with the current drawing color. |
14 | | -- `hellipse(x, y, width, height, thickness)`: Draws a hollow ellipse with the center at `(x, y)`, the specified width and height, and the specified thickness. The ellipse is outlined with the current drawing color. |
15 | | -- `hellipse(x, y, width, height, rotation, thickness)`: Draws a hollow ellipse with the center at `(x, y)`, the specified width and height, the specified rotation in degrees, and the specified thickness. The ellipse is outlined with the current drawing color. |
16 | | -- `polygon(xs, ys)`: Draws a filled polygon with the specified vertices. The polygon is filled with the current drawing color. |
17 | | -- `hpolygon(thickness, xs, ys)`: Draws a hollow polygon with the specified vertices and thickness. The polygon is outlined with the current drawing color. |
18 | | -- `text(x, y, text, font_size)`: Draws the specified text at the position `(x, y)` with the specified font size. The text is drawn with the current drawing color. |
19 | | -- `textured_tri(parse_image_result, xs, ys, us, vs)`: Draws a textured triangle using the specified vertices and texture coordinates. The `parse_image_result` is the result from the `parse_image()` function. |
20 | | -- `stamp()`: Stamps the sprite onto the stage at its current position. The stamp is a copy of the sprite's current appearance, effects included. |
21 | | -- `clear_all_stamps()`: Clears all the stamps on the stage. |
22 | | -- `r()`: Returns the current red component of the drawing color. |
23 | | -- `g()`: Returns the current green component of the drawing color. |
24 | | -- `b()`: Returns the current blue component of the drawing color. |
| 1 | +## `set_color(r, g, b, a)` |
| 2 | +Sets the drawing color to the specified RGBA values. The values are in the range of 0 to 255. |
| 3 | + |
| 4 | +**Properties:** |
| 5 | + |
| 6 | +- `r` (Number): The red component of the color (0-255). |
| 7 | +- `g` (Number): The green component of the color (0-255). |
| 8 | +- `b` (Number): The blue component of the color (0-255). |
| 9 | + |
| 10 | +**Returns:** `null` |
| 11 | + |
| 12 | +## `change_r(increment)` |
| 13 | +Changes the red component of the drawing color by the specified increment. The increment can be positive or negative. |
| 14 | + |
| 15 | +**Properties:** |
| 16 | + |
| 17 | +- `increment` (Number): The amount to change the red component by. |
| 18 | + |
| 19 | +**Returns:** `null` |
| 20 | + |
| 21 | +## `change_g(increment)` |
| 22 | +Changes the green component of the drawing color by the specified increment. The increment can be positive or negative. |
| 23 | + |
| 24 | +**Properties:** |
| 25 | + |
| 26 | +- `increment` (Number): The amount to change the green component by. |
| 27 | + |
| 28 | +**Returns:** `null` |
| 29 | + |
| 30 | +## `change_b(increment)` |
| 31 | +Changes the blue component of the drawing color by the specified increment. The increment can be positive or negative. |
| 32 | + |
| 33 | +**Properties:** |
| 34 | + |
| 35 | +- `increment` (Number): The amount to change the blue component by. |
| 36 | + |
| 37 | +**Returns:** `null` |
| 38 | + |
| 39 | +## `change_a(increment)` |
| 40 | +Changes the alpha (transparency) component of the drawing color by the specified increment. The increment can be positive or negative. |
| 41 | + |
| 42 | +**Properties:** |
| 43 | + |
| 44 | +- `increment` (Number): The amount to change the alpha component by. |
| 45 | + |
| 46 | +**Returns:** `null` |
| 47 | + |
| 48 | +## `line(x1, y1, x2, y2, thickness)` |
| 49 | +Draws a line from the point `(x1, y1)` to the point `(x2, y2)` with the specified thickness. |
| 50 | + |
| 51 | +**Properties:** |
| 52 | + |
| 53 | +- `x1` (Number): The x-coordinate of the starting point. |
| 54 | +- `y1` (Number): The y-coordinate of the starting point. |
| 55 | +- `x2` (Number): The x-coordinate of the ending point. |
| 56 | +- `y2` (Number): The y-coordinate of the ending point. |
| 57 | +- `thickness` (Number): The thickness of the line. |
| 58 | + |
| 59 | +**Returns:** `null` |
| 60 | + |
| 61 | +## `rect(x1, y1, x2, y2)` |
| 62 | +Draws a rectangle with the top-left corner at `(x1, y1)` and the bottom-right corner at `(x2, y2)`. |
| 63 | + |
| 64 | +**Properties:** |
| 65 | + |
| 66 | +- `x1` (Number): The x-coordinate of the top-left corner. |
| 67 | +- `y1` (Number): The y-coordinate of the top-left corner. |
| 68 | +- `x2` (Number): The x-coordinate of the bottom-right corner. |
| 69 | +- `y2` (Number): The y-coordinate of the bottom-right corner. |
| 70 | + |
| 71 | +**Returns:** `null` |
| 72 | + |
| 73 | +## `hrect(x1, y1, x2, y2, thickness)` |
| 74 | +Draws a hollow rectangle with the top-left corner at `(x1, y1)` and the bottom-right corner at `(x2, y2)` with the specified thickness. |
| 75 | + |
| 76 | +**Properties:** |
| 77 | + |
| 78 | +- `x1` (Number): The x-coordinate of the top-left corner. |
| 79 | +- `y1` (Number): The y-coordinate of the top-left corner. |
| 80 | +- `x2` (Number): The x-coordinate of the bottom-right corner. |
| 81 | +- `y2` (Number): The y-coordinate of the bottom-right corner. |
| 82 | +- `thickness` (Number): The thickness of the rectangle outline. |
| 83 | + |
| 84 | +**Returns:** `null` |
| 85 | + |
| 86 | +## `circle(x, y, radius)` |
| 87 | +Draws a filled circle with the center at `(x, y)` and the specified radius. |
| 88 | + |
| 89 | +**Properties:** |
| 90 | + |
| 91 | +- `x` (Number): The x-coordinate of the center of the circle. |
| 92 | +- `y` (Number): The y-coordinate of the center of the circle. |
| 93 | +- `radius` (Number): The radius of the circle. |
| 94 | + |
| 95 | +**Returns:** `null` |
| 96 | + |
| 97 | +## `hcircle(x, y, radius, thickness)` |
| 98 | +Draws a hollow circle with the center at `(x, y)` and the specified radius with the specified thickness. |
| 99 | + |
| 100 | +**Properties:** |
| 101 | + |
| 102 | +- `x` (Number): The x-coordinate of the center of the circle. |
| 103 | +- `y` (Number): The y-coordinate of the center of the circle. |
| 104 | +- `radius` (Number): The radius of the circle. |
| 105 | +- `thickness` (Number): The thickness of the circle outline. |
| 106 | + |
| 107 | +**Returns:** `null` |
| 108 | + |
| 109 | +## `ellipse(x, y, width, height, rotation?)` |
| 110 | +Draws a filled ellipse with the center at `(x, y)` and the specified width and height. Optionally, a rotation in degrees can be specified. |
| 111 | + |
| 112 | +**Properties:** |
| 113 | + |
| 114 | +- `x` (Number): The x-coordinate of the center of the ellipse. |
| 115 | +- `y` (Number): The y-coordinate of the center of the ellipse. |
| 116 | +- `width` (Number): The width of the ellipse. |
| 117 | +- `height` (Number): The height of the ellipse. |
| 118 | +- `rotation` (Number, optional): The rotation of the ellipse in degrees. |
| 119 | + |
| 120 | +**Returns:** `null` |
| 121 | + |
| 122 | +## `hellipse(x, y, width, height, rotation?, thickness)` |
| 123 | +Draws a hollow ellipse with the center at `(x, y)`, the specified width and height, and the specified thickness. Optionally, a rotation in degrees can be specified. |
| 124 | + |
| 125 | +**Properties:** |
| 126 | + |
| 127 | +- `x` (Number): The x-coordinate of the center of the ellipse. |
| 128 | +- `y` (Number): The y-coordinate of the center of the ellipse. |
| 129 | +- `width` (Number): The width of the ellipse. |
| 130 | +- `height` (Number): The height of the ellipse. |
| 131 | +- `rotation` (Number, optional): The rotation of the ellipse in degrees. |
| 132 | +- `thickness` (Number): The thickness of the ellipse outline. |
| 133 | + |
| 134 | +**Returns:** `null` |
| 135 | + |
| 136 | +## `polygon(xs, ys)` |
| 137 | +Draws a filled polygon with the specified vertices. |
| 138 | +!!! warning |
| 139 | + The polygon can only be convex (no inward dents) and should be wounded counter-clockwise. |
| 140 | + |
| 141 | +**Properties:** |
| 142 | + |
| 143 | +- `xs` (List of Numbers): The x-coordinates of the vertices. |
| 144 | +- `ys` (List of Numbers): The y-coordinates of the vertices. |
| 145 | + |
| 146 | +**Returns:** `null` |
| 147 | + |
| 148 | +## `hpolygon(thickness, xs, ys)` |
| 149 | +Draws a hollow polygon with the specified vertices and thickness. |
| 150 | +!!! warning |
| 151 | + The polygon can only be convex (no inward dents) and should be wounded counter-clockwise. |
| 152 | + |
| 153 | +**Properties:** |
| 154 | + |
| 155 | +- `thickness` (Number): The thickness of the polygon outline. |
| 156 | +- `xs` (List of Numbers): The x-coordinates of the vertices. |
| 157 | +- `ys` (List of Numbers): The y-coordinates of the vertices. |
| 158 | + |
| 159 | +**Returns:** `null` |
| 160 | + |
| 161 | +## `text(x, y, text, font_size)` |
| 162 | +Draws the specified text at the position `(x, y)` with the specified font size. |
| 163 | + |
| 164 | +**Properties:** |
| 165 | + |
| 166 | +- `x` (Number): The x-coordinate of the position to draw the text. |
| 167 | +- `y` (Number): The y-coordinate of the position to draw the text. |
| 168 | +- `text` (String): The text to draw. |
| 169 | +- `font_size` (Number): The font size of the text. |
| 170 | + |
| 171 | +**Returns:** `null` |
| 172 | + |
| 173 | +## `textured_tri(parse_image_result, xs, ys, us, vs)` |
| 174 | +Draws a textured triangle using the specified vertices and texture coordinates. |
| 175 | + |
| 176 | +**Properties:** |
| 177 | + |
| 178 | +- `parse_image_result` (List): The result from the `parse_image()` function. Alternatively, you can construct this manually by creating a list like: |
| 179 | + ``` |
| 180 | + [ |
| 181 | + image_width, |
| 182 | + image_height, |
| 183 | + [R, G, B, A, R, G, B, A, ...], // Pixel data as a flat list |
| 184 | + ] |
| 185 | + ``` |
| 186 | +- `xs` (List of Numbers): The x-coordinates of the triangle vertices. |
| 187 | +- `ys` (List of Numbers): The y-coordinates of the triangle vertices. |
| 188 | +- `us` (List of Numbers): The u texture coordinates of the triangle vertices. |
| 189 | +- `vs` (List of Numbers): The v texture coordinates of the triangle vertices. |
| 190 | +
|
| 191 | +**Returns:** `null` |
| 192 | +
|
| 193 | +## `stamp()` |
| 194 | +Stamps the sprite onto the stage at its current position. The stamp is a copy of the sprite's current appearance, effects included. |
| 195 | +
|
| 196 | +**Properties:** none |
| 197 | +
|
| 198 | +**Returns:** `null` |
| 199 | +
|
| 200 | +## `clear_all_stamps()` |
| 201 | +Clears all the stamps on the stage. |
| 202 | +
|
| 203 | +**Properties:** none |
| 204 | +
|
| 205 | +**Returns:** `null` |
| 206 | +
|
| 207 | +## `r()` |
| 208 | +Returns the current red component of the drawing color. |
| 209 | +
|
| 210 | +**Properties:** none |
| 211 | +
|
| 212 | +**Returns:** `Number` - The red component of the drawing color (0-255). |
| 213 | +
|
| 214 | +## `g()` |
| 215 | +Returns the current green component of the drawing color. |
| 216 | +
|
| 217 | +**Properties:** none |
| 218 | +
|
| 219 | +**Returns:** `Number` - The green component of the drawing color (0-255). |
| 220 | +
|
| 221 | +## `b()` |
| 222 | +Returns the current blue component of the drawing color. |
| 223 | +
|
| 224 | +**Properties:** none |
| 225 | +
|
| 226 | +**Returns:** `Number` - The blue component of the drawing color (0-255). |
| 227 | +
|
| 228 | +## `a()` |
| 229 | +Returns the current alpha (transparency) component of the drawing color. |
| 230 | +
|
| 231 | +**Properties:** none |
| 232 | +
|
| 233 | +**Returns:** `Number` - The alpha component of the drawing color (0-255). |
25 | 234 |
|
26 | 235 | !!! note |
27 | 236 | The drawing functions draw in world coordinates, not screen coordinates. The origin `(0, 0)` is at the center of the screen, with positive x values to the right and positive y values upwards. |
0 commit comments