Skip to content

🪲 Fix downloading the turtle drawings and make them faster - #6736

Merged
jpelay merged 10 commits into
mainfrom
fix-turtle-download-6548-recording
Oct 23, 2026
Merged

jpelay merged 10 commits into
mainfrom
fix-turtle-download-6548-recording

Conversation

@jpelay

@jpelay jpelay commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Fixes the turtle png and dst downloads by storing locally the points the turtle draws and send that information back to the server, in turn the server just needs to process these points and serve the file.

It's a lot faster than what we had because the server doesn't need to run the program again, we dont need to store anything in the server.

Also fixes the embroidery files by making the drawing bigger, and without suffering from the problem of being mirrored.

Fixes #6548

How to test

  • Go to a level with the turtle, write a turtle program and run it. Verify that the "Save turtle drawing" button shows up after the program finishes, and that it doesn't show up for programs without the turtle.
  • Click the button and verify that hedy_drawing.zip downloads, containing hedy_drawing.dst and hedy_drawing.png.
  • Open the PNG and verify it matches the drawing on screen. E.g. in level 1, forward 100, turn right, forward 50 should look like a Γ, not an L (before this PR drawings came out upside down).
  • Try a few programs that failed before:
    • Level 2, ask: distance is ask How far? / forward distance. The file should use the answer you typed.
    • Level 3, random: angles is 90, 180 / turn angles at random / forward 50. The file should match the drawing you got on screen.
    • Level 5 if, level 12 define with decimals, level 14 while.
  • Run a turtle program with the debugger until it finishes and verify the download also works.
  • Automated tests: pytest tests/python_html/test_app_routes.py -k MachineAndMicrobit and the Cypress spec tests/cypress/e2e/hedy_page/save_turtle_drawing.cy.js.

@AnneliesVlaar

Copy link
Copy Markdown
Collaborator

@jpelay the dst download we currently have is not useful for embroidery machines. That is because 10 turtle steps corresponds to 1 mm in the library turtlethread. And most of our turtle drawings are in the order of magnitude of 10 steps.

For example creating this boat:
https://hedy-alpha.herokuapp.com/hedy/2#turtle_draw_it

turn -90
forward 55
turn  45
forward 60
turn 135
forward 70
turn -90
forward 60
turn 135
forward 25
turn 90
forward 25
turn -45
forward 24
turn -90
forward 70
turn 135
forward 60

results in a embroidery of 1 by 1.4 cm.

My suggestion would be to use the scale functionality (https://turtlethread.com/en/api/turtle.html) to scale the steps by 4:
t = Turtle(scale=4)
Then the height of the turtle canvas (250) is equal to 10 cm (typical maximum embroidery-machine-size).
We should then also change the stitch size, for example to stitch every 5 steps (every 2 mm typical stitch size for embroidery machines):
with t.running_stitch(stitch_length=5):

@jpelay

jpelay commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

Hello @AnneliesVlaar! Thank you for the suggestion! Can you check now?

@jpelay
jpelay merged commit 0efd87a into main Oct 23, 2026
16 checks passed
@jpelay
jpelay deleted the fix-turtle-download-6548-recording branch October 23, 2026 14:42
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Hedy organization board Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done
Status: Review for relevance

Development

Successfully merging this pull request may close these issues.

🪲Fix download turtle drawings

2 participants