Skip to content

Commit 05756d6

Browse files
New documentation
1 parent 879ea17 commit 05756d6

15 files changed

Lines changed: 2025 additions & 239 deletions

docs/control.md

Lines changed: 103 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,103 @@
1-
Most of the control functions are block statements and explained in the [Crust Language](crust-language.md) page. Here is a list of all the control functions in Crust:
2-
3-
- `wait(time)`: Waits for the specified time in seconds before continuing to the next block.
4-
- `stop(option)`: Stops the current script. The `option` can be `all`, `this`, `script`, `other-scripts`, or `other-sprites-and-scripts`:
5-
- `all`: Stops all scripts in all sprites.
6-
- `this`: Stops all scripts in the current sprite.
7-
- `script`: Stops the current script.
8-
- `other-scripts`: Stops all scripts in the current sprite.
9-
- `other-sprites-and-scripts`: Stops all scripts in all sprites and all scripts in the current sprite except the current script.
10-
- `clone()`: Creates a clone of the sprite. The clone will execute the `clone_setup` and `clone_update` blocks.
11-
- `delete_clone()`: Deletes the current clone. This function is typically called within the `clone_update` block to remove the clone when it is no longer needed.
12-
- `delete_clone(cloneid)`: Deletes the specified clone. The `cloneid` is the ID of the clone to delete, which starts from 1 and increments for each clone created.
13-
- `skip_further_execution_if(bool)`: Skips the execution of the current script if the condition is true.
14-
15-
This page is so short unlike others...
1+
## `wait(time)`
2+
Waits for a duration.
3+
4+
**Properties:**
5+
6+
- `time` (Number): Time to wait in seconds.
7+
8+
**Returns:** `null`
9+
10+
## `stop(option)`
11+
Stops the specified script(s).
12+
13+
**Properties:**
14+
15+
- `option` (String): What to stop. Available options:
16+
- `"all"`: Stops all scripts in all sprites.
17+
- `"this"`: Stops all scripts in the current sprite.
18+
- `"script"`: Stops the current script.
19+
- `"other-scripts"`: Stops all other scripts in the current sprite.
20+
- `"other-sprites-and-scripts"`: Stops all other scripts in all sprites.
21+
22+
**Returns:** `null`
23+
!!! example
24+
```
25+
setup { // A setup script
26+
// Something
27+
stop("this") // Stop this script
28+
// Stuff here will not be executed
29+
}
30+
```
31+
32+
## `clone()`
33+
Clones the sprite. The clone will execute the `clone_setup` and `clone_update` scripts.
34+
!!! warning
35+
Clones are also sprites. Excessive cloning can and will lead to performance issues.
36+
37+
**Properties:** none
38+
39+
**Returns:** `null`
40+
!!! example
41+
```
42+
setup {
43+
clone()
44+
}
45+
update {}
46+
clone_setup {
47+
// This will not be printed by the original sprite, but by the clone
48+
print("Hello, I'm a clone!")
49+
}
50+
clone_update {}
51+
```
52+
53+
## `delete_clone()` / `delete_clone(cloneid)`
54+
Deletes a clone.
55+
56+
=== "`delete_clone()`"
57+
Deletes the current clone that is running the function. If called on a non-clone sprite, does nothing.
58+
59+
**Properties:** none
60+
61+
**Returns:** `null`
62+
!!! example
63+
```
64+
clone_update {
65+
// Some code
66+
if dont_want_to_exist_anymore {
67+
delete_clone() // Delete this clone
68+
}
69+
}
70+
```
71+
72+
=== "`delete_clone(cloneid)`"
73+
Deletes the specified clone by its ID from its parent sprite.
74+
75+
**Properties:**
76+
77+
- `cloneid` (Number): The ID of the clone to delete. Clone IDs start from 1 and increment for each clone created.
78+
79+
**Returns:** `null`
80+
!!! example
81+
```
82+
setup {
83+
clone() // Create a clone
84+
clone() // Create another clone
85+
delete_clone(1) // Delete the first clone created
86+
}
87+
```
88+
89+
## `skip_further_execution_if(bool)`
90+
Skips further execution of the current script if the condition is true.
91+
92+
**Properties:**
93+
94+
- `bool` (Boolean): Condition to check.
95+
96+
**Returns:** `null`
97+
!!! example
98+
```
99+
update {
100+
skip_further_execution_if(score < 10)
101+
print("Score is 10 or more!")
102+
}
103+
```

docs/drawing.md

Lines changed: 233 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,236 @@
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).
25234
26235
!!! note
27236
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

Comments
 (0)