File size: 1,310 Bytes
8fe65d4
 
 
 
 
915ca9b
8fe65d4
 
 
 
 
 
 
 
 
915ca9b
8fe65d4
 
 
 
 
 
 
 
 
 
 
915ca9b
8fe65d4
 
 
 
 
915ca9b
8fe65d4
915ca9b
8fe65d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
915ca9b
8fe65d4
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# /// script
# requires-python = "==3.12"
# dependencies = [
#     "anywidget",
#     "marimo",
#     "marimo-learn==0.13.0",
# ]
# ///

"""
Example Marimo Notebook: Turtle Graphics
"""

import marimo

__generated_with = "0.23.1"
app = marimo.App()


@app.cell
def _():
    import marimo as mo
    from marimo_learn import (
        Color,
        World,
    )

    return Color, World, mo


@app.cell
def _(mo):
    mo.md("""
    # Turtle Graphics

    The [marimo-learn](https://pypi.org/project/marimo-learn/) package includes a simple implementation of turtle graphics. Learners can create worlds, and then write functions to make a turtle draw multi-colored shapes. Crucially, this widget was created in only 15 minutes with the assistance of an LLM, which shows just how easy it now is for educators to create tools that meet their specific needs.
    """)
    return


@app.cell
def _(Color, World, mo):
    _world = World()

    async def _spiral(world, turtle):
        colors = list(Color)
        for i in range(70):
            if i % 10 == 0:
                turtle.set_color(colors[(i // 10) % len(colors)])
            await turtle.forward(i * 2.8)
            turtle.right(91)

    _world.set_coroutine(_spiral)
    mo.ui.anywidget(_world)
    return


if __name__ == "__main__":
    app.run()