 # [HELP] Snowflakes on the Ice

Each time I run my code I get this error: This is my code:

``````# For this level we need to a line fractal for the ground and a hexagonal snowflake made up of 6 line fractals. Check the guide for an image of the desired output.

# All vector operations require working in radians rather than degrees.
return Math.PI / 180 * degrees

# This function creates a line fractal.  Read through it so you understand the recursive concept.
def line(start, end):
# First we need to get the full vector and its magnitude to determine if we are below our minimum threshold.
full = Vector.subtract(end, start)
distance = full.magnitude()
if distance < 4:
# If under our threshold distance, then we will simply draw a line along the vector and be done (the return tells us to exit the function).
hero.toggleFlowers(False)
hero.moveXY(start.x, start.y)
hero.toggleFlowers(True)
hero.moveXY(end.x, end.y)
return

# Otherwise we will create our fractal by getting a vector of half magnitude.
half = Vector.divide(full, 2)

# We will be creating 4 line fractals (start -> A, A -> B, B -> A, and A -> end) and so we need to calculate the intermediate positions A and B.

# To get B, we need to rotate the vector half 90 degrees and multiply by 2/3 (so it is 1/3 of the original magnitude), then add this to A.
rotate = Vector.multiply(rotate, 2 / 3)

# Now just draw the 4 lines using the line functions.
line(start, A)
line(A, B)
line(B, A)
line(A, end)

def flake(start, end):
# To create a hexagonal flake we need to create 6 line fractals rotated by 60 degrees each time.
side = Vector.subtract(end, start)
a = start
b = end
for i in range(6):
line(a, b)
# To get the next edge, we need to rotate the side 60 degrees.
# Now need to reset a and b with the beginning and end points for the new side.
a = start
b = end

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

# You need to actually call the functions with a start and end vector for each.
line((12,10), (60, 10))
# Be sure to use actual Vector objects–simple objects will not work.
flake((52,52),(64,52))
# Refresh often to avoid a memory leak and crash (working on it)

``````

For statement ‘rotate = Vector.rotate(side, degreesToRadian(60))’, what is the actual name of the function you are calling?

Two lines down, you have ‘a = start’, but have already defined a = start a few lines above. Instead, you need to re-define a to equal the new starting point, which happens to be the old end point.

So I need to redefine my a and b

Correct.

Also, at the end of your code, you are calling both the ‘line’ and ‘flake’ functions, but are passing the coordinates as x,y values, rather than vectors. To get your method to work, pass the coords as a vector, like:

``````line(Vector(12,10), Vector(60, 10))
``````

Be sure to double check your values when you call ‘flake’ tho…you currently have them transposed. Otherwise, it would be best to make use of the whiteXs and redXs you defined just above. Both of these are set up as arrays, containing two elements each. redXs and redXs for example. These values are already represented as vectors. So the corresponding code for that wold be:

``````line(whiteXs, whiteXs)
``````

Back in your ‘flake’ function, you are defining ‘rotate’ to equal ‘Vector.rotate()’…notice that the function is actually working with just three variables, a, b, side? Rotate is not used anywhere else in this function, so is actually doing nothing here.

Finally, once you have properly re-defined the value of b (hint…it is not ‘= end’), you need to indent that statement, so that it aligns with the other child statements in the for loop.

What happens is that I get the line fractal and then my hero stops at the hexagonal flake. This is my code:

``````# For this level we need to a line fractal for the ground and a hexagonal snowflake made up of 6 line fractals. Check the guide for an image of the desired output.

# All vector operations require working in radians rather than degrees.
return Math.PI / 180 * degrees

# This function creates a line fractal.  Read through it so you understand the recursive concept.
def line(start, end):
# First we need to get the full vector and its magnitude to determine if we are below our minimum threshold.
full = Vector.subtract(end, start)
distance = full.magnitude()
if distance < 4:
# If under our threshold distance, then we will simply draw a line along the vector and be done (the return tells us to exit the function).
hero.toggleFlowers(False)
hero.moveXY(start.x, start.y)
hero.toggleFlowers(True)
hero.moveXY(end.x, end.y)
return

# Otherwise we will create our fractal by getting a vector of half magnitude.
half = Vector.divide(full, 2)

# We will be creating 4 line fractals (start -> A, A -> B, B -> A, and A -> end) and so we need to calculate the intermediate positions A and B.

# To get B, we need to rotate the vector half 90 degrees and multiply by 2/3 (so it is 1/3 of the original magnitude), then add this to A.
rotate = Vector.multiply(rotate, 2 / 3)

# Now just draw the 4 lines using the line functions.
line(start, A)
line(A, B)
line(B, A)
line(A, end)

def flake(start, end):
# To create a hexagonal flake we need to create 6 line fractals rotated by 60 degrees each time.
side = Vector.subtract(end, start)
a = start
b = end
for i in range(6):
line(a, b)
# To get the next edge, we need to rotate the side 60 degrees.
# Now need to reset a and b with the beginning and end points for the new side.
a = end
b = end

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

# You need to actually call the functions with a start and end vector for each.
line(Vector(12,10), Vector(60, 10))
# Be sure to use actual Vector objects–simple objects will not work.
flake(Vector(52,52),Vector(64,52))
# Refresh often to avoid a memory leak and crash (working on it)

``````

You did get a couple of them, but this still needs work:

Be sure to double check your values when you call ‘flake’ tho…you currently have them transposed. Otherwise, it would be best to make use of the whiteXs and redXs you defined just above. Both of these are set up as arrays, containing two elements each. redXs and redXs for example. These values are already represented as vectors. So the corresponding code for that wold be:

``````line(whiteXs, whiteXs)
``````

Back in your ‘flake’ function, you are defining ‘rotate’ to equal ‘Vector.rotate()’…notice that the function is actually working with just three variables, a, b, side? Rotate is not used anywhere else in this function, so is actually doing nothing here.

I change this:

``````line(Vector(12,10), Vector(60, 10))
# Be sure to use actual Vector objects–simple objects will not work.
flake(Vector(52,52),Vector(64,52))
``````

to this

``````line(whiteXs, whiteXs)
# Be sure to use actual Vector objects–simple objects will not work.
flake(redXs, redXs)
``````

How do I rotate my hero

Now I get two sides of the hexagonal flake, and my hero keeps repeating the last one and I get incomplete

instead of naming a new variable, re-define an existing one. ‘side’ is the only one that has not been adjusted so far.

oh man i wish i could help you but i cannot because my account on code combat is lost and/or g for good!               what do you mean by this:

My code:

``````# For this level we need to a line fractal for the ground and a hexagonal snowflake made up of 6 line fractals. Check the guide for an image of the desired output.

# All vector operations require working in radians rather than degrees.
return Math.PI / 180 * degrees

# This function creates a line fractal.  Read through it so you understand the recursive concept.
def line(start, end):
# First we need to get the full vector and its magnitude to determine if we are below our minimum threshold.
full = Vector.subtract(end, start)
distance = full.magnitude()
if distance < 4:
# If under our threshold distance, then we will simply draw a line along the vector and be done (the return tells us to exit the function).
hero.toggleFlowers(False)
hero.moveXY(start.x, start.y)
hero.toggleFlowers(True)
hero.moveXY(end.x, end.y)
return

# Otherwise we will create our fractal by getting a vector of half magnitude.
half = Vector.divide(full, 2)

# We will be creating 4 line fractals (start -> A, A -> B, B -> A, and A -> end) and so we need to calculate the intermediate positions A and B.

# To get B, we need to rotate the vector half 90 degrees and multiply by 2/3 (so it is 1/3 of the original magnitude), then add this to A.
rotate = Vector.multiply(rotate, 2 / 3)

# Now just draw the 4 lines using the line functions.
line(start, A)
line(A, B)
line(B, A)
line(A, end)

def flake(start, end):
# To create a hexagonal flake we need to create 6 line fractals rotated by 60 degrees each time.
side = Vector.subtract(end, start)
a = start
b = end
for i in range(6):
line(a, b)
# To get the next edge, we need to rotate the side 60 degrees.
# Now need to reset a and b with the beginning and end points for the new side.
line(start, b)
line(b, a)
line(a, b)
line(b,a)
line(a,b)
line(a, end)

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

# You need to actually call the functions with a start and end vector for each.
line(whiteXs, whiteXs)
# Be sure to use actual Vector objects–simple objects will not work.
flake(redXs, redXs)
# Refresh often to avoid a memory leak and crash (working on it)

``````

1 Like

give me the link to the level
-Zax

Here:

I mean: you are creating ‘rotate’ (defining it), but then not using it anywhere. Instead, you need to redefine ‘side’.

``````side = Vector...... #and the rest of the statement, as you had it.
``````

With the corrections, your original code was just about there. As you might recall, you asked ‘so I need to redefine my a and b?’…you don’t need all of the extra code from your last post.

Think of it this way: You begin at ‘start’ and wind up at ‘end’. However, to manage the work between those two points, you are also using ‘a’ and ‘b’. So, at the beginning, ‘a = start’ and ‘b = end’…you draw that line, between ‘a’ and ‘b’. Now, ‘b’ is actually your new start point, since you will be starting your next line where you ended that last one…‘a’ is your working starting point variable, so you need to update (redefine) ‘a’, as ‘b’; you also need to calculate where the next ending point is and assign it to the variable ‘b’. To do this, you need to calculate the vector…you do this with:

``````b = Vector.add(side, a)
``````

This is my new code:

``````# For this level we need to a line fractal for the ground and a hexagonal snowflake made up of 6 line fractals. Check the guide for an image of the desired output.

# All vector operations require working in radians rather than degrees.
return Math.PI / 180 * degrees

# This function creates a line fractal.  Read through it so you understand the recursive concept.
def line(start, end):
# First we need to get the full vector and its magnitude to determine if we are below our minimum threshold.
full = Vector.subtract(end, start)
distance = full.magnitude()
if distance < 4:
# If under our threshold distance, then we will simply draw a line along the vector and be done (the return tells us to exit the function).
hero.toggleFlowers(False)
hero.moveXY(start.x, start.y)
hero.toggleFlowers(True)
hero.moveXY(end.x, end.y)
return

# Otherwise we will create our fractal by getting a vector of half magnitude.
half = Vector.divide(full, 2)

# We will be creating 4 line fractals (start -> A, A -> B, B -> A, and A -> end) and so we need to calculate the intermediate positions A and B.

# To get B, we need to rotate the vector half 90 degrees and multiply by 2/3 (so it is 1/3 of the original magnitude), then add this to A.
rotate = Vector.multiply(rotate, 2 / 3)

# Now just draw the 4 lines using the line functions.
line(start, A)
line(A, B)
line(B, A)
line(A, end)

def flake(start, end):
# To create a hexagonal flake we need to create 6 line fractals rotated by 60 degrees each time.
side = Vector.subtract(end, start)
a = start
b = end
for i in range(6):
line(a, b)
# To get the next edge, we need to rotate the side 60 degrees.
# Now need to reset a and b with the beginning and end points for the new side.
line(start, b)
line(b, a)
line(a, b)
line(b,a)
line(a,b)
line(a, end)

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

# You need to actually call the functions with a start and end vector for each.
line(whiteXs, whiteXs)
# Be sure to use actual Vector objects–simple objects will not work.
flake(redXs, redXs)
# Refresh often to avoid a memory leak and crash (working on it)

``````

Now, it still keeps going back and forth on the hexagonal flake, the first side.

i cannot help i am sorry i am not a subscribier!!
-Zax

I don’t think you are listening to what I’m trying to help you with…good luck with this level. Let’s hope someone just doesn’t give you the code, as you will have learned nothing that way.