Skip to content Skip to sidebar Skip to footer

Need Help Making A Hilbert Curve Using Numbers In Python

I want to make a function that will create a Hilbert Curve in python using numbers. The parameters for the function would be a number and that will tell the function how many times

Solution 1:

In the code you provided you are testing with # 1 as input. In this case:

for i in range(num-1):

is not fulfilled and your for-loop is never initialized since your i is already past that range.

Below you can see a sample code that you can use as reference when playing with Hilbert Curve:

import turtle

turtle.speed(speed=10)  # Fastest

hilbert_seq = "a"for _ inrange(5):
    new_seq = ""forcharin hilbert_seq:
        ifchar == "a":
            new_seq += "-bF+aFa+Fb-"
        elif char == "b":
            new_seq += "+aF-bFb-Fa+"else:
            new_seq += char
    hilbert_seq = new_seq

forcharin hilbert_seq:
    ifchar == "F":
        turtle.forward(9)
    elif char == "+":
        turtle.right(90)
    elif char == "-":
        turtle.left(90)

Screenshot from the above sample code:

Screenshot of running turtle graphics implementation of the Hilbert Curve

Post a Comment for "Need Help Making A Hilbert Curve Using Numbers In Python"