Skip to content

Commit

Permalink
[LANGUAGE] Add clear to turtle (hedyorg#3992)
Browse files Browse the repository at this point in the history
Fixes hedyorg#3991.
Fun example to test in level 9:
```python
print "Lets Draw!"

repeat 30 times
    if w is pressed
        forward 20
    if a is pressed
        turn -90
    if d is pressed
        turn 90
    if x is pressed
        clear
        print "Cleared!"
```

When using the _clear_ keyword it should now also clear the turtle canvas.
  • Loading branch information
ToniSkulj authored Jan 31, 2023
1 parent b9e3e97 commit d0da872
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion hedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,15 @@ def error_print_nq(self, meta, args):
return ConvertToPython_2.print(self, meta, args)

def clear(self, meta, args):
return 'extensions.clear()'
return f"""extensions.clear()
try:
# If turtle is being used, reset canvas
t.hideturtle()
turtle.resetscreen()
t.left(90)
t.showturtle()
except NameError:
pass"""


@v_args(meta=True)
Expand Down
12 changes: 11 additions & 1 deletion tests/test_level/test_level_04.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,5 +638,15 @@ def test_lonely_text(self):

def test_clear(self):
code = "clear"
expected = "extensions.clear()"
expected = textwrap.dedent("""\
extensions.clear()
try:
# If turtle is being used, reset canvas
t.hideturtle()
turtle.resetscreen()
t.left(90)
t.showturtle()
except NameError:
pass""")

self.multi_level_tester(code=code, expected=expected)

0 comments on commit d0da872

Please sign in to comment.