Created
July 23, 2025 19:27
-
-
Save TwoSquirrels/070429e68b3595dd393eb767e58a2def to your computer and use it in GitHub Desktop.
Hilbert curve drawer for Computer Craft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- SPDX-FileCopyrightText: 2025 TwoSquirrels | |
| -- SPDX-License-Identifier: MIT | |
| function forward(steps) | |
| for i = 1, steps do | |
| for slot = 1, 16 do | |
| if turtle.getItemCount(slot) > 0 then | |
| turtle.select(slot) | |
| turtle.placeDown() | |
| break | |
| end | |
| end | |
| if turtle.detect() then | |
| turtle.dig() | |
| end | |
| turtle.forward() | |
| end | |
| end | |
| function up(steps) | |
| for i = 1, steps do | |
| if turtle.detectUp() then | |
| turtle.digUp() | |
| end | |
| turtle.up() | |
| end | |
| end | |
| function down(steps) | |
| for i = 1, steps do | |
| if turtle.detectDown() then | |
| turtle.digDown() | |
| end | |
| turtle.down() | |
| end | |
| end | |
| function hilbertCurveX(level, step) | |
| if level == 0 then | |
| return | |
| end | |
| turtle.turnLeft() | |
| hilbertCurveY(level - 1, step) | |
| forward(step) | |
| turtle.turnRight() | |
| hilbertCurveX(level - 1, step) | |
| forward(step) | |
| hilbertCurveX(level - 1, step) | |
| turtle.turnRight() | |
| forward(step) | |
| hilbertCurveY(level - 1, step) | |
| turtle.turnLeft() | |
| end | |
| function hilbertCurveY(level, step) | |
| if level == 0 then | |
| return | |
| end | |
| turtle.turnRight() | |
| hilbertCurveX(level - 1, step) | |
| forward(step) | |
| turtle.turnLeft() | |
| hilbertCurveY(level - 1, step) | |
| forward(step) | |
| hilbertCurveY(level - 1, step) | |
| turtle.turnLeft() | |
| forward(step) | |
| hilbertCurveX(level - 1, step) | |
| turtle.turnRight() | |
| end | |
| print("Start to draw Hilbert curve") | |
| up(80) | |
| hilbertCurveX(4, 4) | |
| down(80) | |
| print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment