[SOLVED] Problem with Snowflakes on the ice

Hello!
The only problem I have here is that my hero can’t draw a flake.
Here is my code:

# На этот уровне нам понадобится линейный фрактал, как основа для нашей шестиугольной снежинки. Сама снежинка будет состоять из 6 линейных фракталов. Обратись к описанию за инструкцией и изображением желаемого результата.

def degreesToRadians(degrees):
    # Все векторные операции предпочтительнее выполнять в радианах, нежели в градусах.
    return Math.PI / 180 * degrees
    
# Это функция создает линейный фрактал. Вчитайся в код, чтобы понять концепцию рекурсии.
def line(start, end):
    # Для начала нам необходимо получить размер полного вектора, чтобы проверить его на минимальный порог.
    full = Vector.subtract(end, start) 
    distance = full.magnitude()
    if distance < 4:
        # Если ниже порогового размера, то просто построим линию вдоль вектора и закончим (возврат из функции).
        hero.toggleFlowers(False)
        hero.moveXY(start.x, start.y)
        hero.toggleFlowers(True)
        hero.moveXY(end.x, end.y)
        return
        
    # Иначе мы создадим наш фрактал, используя вектор половинной длины.
    half = Vector.divide(full, 2)
    
    # Мы создадим 4 линейных фрактала (старт -> А, А -> В, В -> А, и А -> конец), следовательно, нужно будет рассчитать промежуточные позиции А и В.
    A = Vector.add(half, start)
    
    # Чтобы получить В, необходимо развернуть половину вектора на 90 градусов и умножить на 2/3 (в итоге получится 1/3 полной длины вектора), после прибавить полученный вектор к А.
    rotate = Vector.rotate(half, degreesToRadians(90))
    rotate = Vector.multiply(rotate, 2 / 3)
    B = Vector.add(rotate, A)
    # Теперь просто построй 4 линии, используя функции линий.
    line(start, A)
    line(A, B)
    line(B, A)
    line(A, end)


def flake(start, end):
    # Для создания шестиугольной снежинки нужно создать 6 линейных фракталов, каждый раз поворачивая на 60 градусов.
    side = Vector.subtract(end, start)
    a = start
    b = end
    for i in range(6):
        line(a, b)
        # Чтобы получить следующую грань, необходимо развернуть сторону на 60 градусов.
        side =  Vector.rotate(side, degreesToRadians(60))
        # Теперь нужно переназначить `a` и `b` на начальную и конечную точки новой стороны.
        a = side.end
        b = side.start

whiteXs = [Vector(12, 10), Vector(60, 10)]
redXs = [Vector(64, 52), Vector(52, 52)]

# Для построения граней придётся вызывать функции с указанием начального и конечного вектора.
line(whiteXs[0], whiteXs[1])
# Используй объекты `Vector`, простые объекты в данном случае не подойдут.
flake(redXs[0], redXs[1])
# Refresh often to avoid a memory leak and crash (working on it)

Here is an error:

this may make you sad but I can not read what the error is can you translate?

TypeError: e is undefined.

Hi Anonym,

These two lines are the problem.

Remember that a and b represent the start and end of the second (and third/fourth/fifth/sixth) side. How do you write this in code?

Jenny

I don’t know how to write the start and the end of the Vector: There are Vector.x, Vector.y, and even Vector.z.How to write the start and the end of the Vector?

So ‘a’ (the start point of the new side) is the end point of the old side. What do you already have that’s the end (remember that you want to use a variable that updates each time)?

For ‘b’, you want to add (Vector.add) two variables to set the new end point of the sides. A hint - both the things you add are variables that you have already defined in your function.

Jenny

1 Like
a = b
b = Vector.add(a, side)

Is that right?

Try it :grin:. Does it work?

Jenny

Yes, it does!Thanks a lot! :grin:

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.