Polygonception - someone can help?

Who can help?every time only two yaks are successfully encircled，and I can’t pass this level

``````# You are on your own this time, I hope you have learned what you need from the previous fractal levels. Check the guide for help with what you need to do and with the math required for polygons.

# You need a function to convert degrees to radians.  Multiply degrees by Math.PI / 180.
return Math.PI / 180 * angle

# Your polygon function should have 3 inputs: start, end, and sides.
def line(start,end,n,k):
side = Vector.subtract(end,start)
distance = side.magnitude()
if distance < k / n + 1:
hero.toggleFlowers(False)
hero.moveXY(start.x, start.y)
hero.toggleFlowers(True)
hero.moveXY(end.x, end.y)
return
fenxing = Vector.divide(side, n)
for i in range(n):
rotate = Vector.rotate(fenxing, degreesToRadians(360 * i / n))
line(start,A,n,k)
start = A
# Remember to make your polygon recursive, drawing extra polygons at every corner.
# To get the start and end position for each polygon, add startOffset and endOffset to the yak's position.
def flake(a,b,n):
side = Vector.subtract(b,a)
k = side.magnitude()
for i in range(n):
line(a,b,n,k)
hero.toggleFlowers(True)
hero.moveXY(b.x, b.y)
a = b

startOffset = Vector(-15, -15)
endOffset = Vector(15, -15)

# You need to loop through all the yaks, drawing a polygon for each.  Yaks are enemies.
enemies = hero.findEnemies()
for enemy in enemies:
sides = enemy.sides
vecEnemy = Vector(enemy.pos.x,enemy.pos.y)
flake(start,end,sides)
``````

Can someone help this fella here?
-@Chaboi_3000

Sorry @jxcwzk I’m terrible at recursion. I know @Chaboi_3000 has done this level.

1 Like

I’ll get to this topic once I’m back from my trip.

I was fainted and This level does afflict people

Just be patient, and we’ll work on this when we have the time.

@jxcwzk Were you able to complete this level? I changed two lines of code on yours and did get all four yaks. I can’t necessarily explain why it worked exactly, but it did.

not yet…and i studying Raspberry Pi

The hints say to have the distance less than 2, but I can’t seem to get that to work. It ends up adding extra recursive and I saw another post commenting on the same thing.

The two lines I changed to make it work:

``````if distance < k / n + 1: # changed to < 10: