# Polygonception - someone can help?

**URL:** <https://discourse.codecombat.com/t/polygonception-someone-can-help/17952>\
**Category:** Level Help\
**Created:** [March 21, 2019, 2:36am UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952 "2019-03-21T02:36:09Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jxcwzk](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jxcwzk](https://discourse.codecombat.com/u/jxcwzk)\
**Post date:** [March 21, 2019, 2:36am UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952/1 "2019-03-21T02:36:09Z")

</div>

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

```python
# 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.
def degreesToRadians(angle):
    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))
        A = Vector.add(rotate,start)
        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)
        side = Vector.rotate(side,degreesToRadians(360 / n))
        a = b
        b = Vector.add(b,side)

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)
    start = Vector.add(vecEnemy,startOffset)
    end = Vector.add(vecEnemy,endOffset)
    flake(start,end,sides)

```

 ![%E6%8D%95%E8%8E%B7](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/d/d4ab8517027d332ab006296f56c4a10461274ecd.jpeg)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [March 27, 2019, 3:30am UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952/2 "2019-03-27T03:30:07Z")

</div>

Automatically bumped on March 27, 2019, 3:30am UTC

Can someone help this fella here?  
-@Chaboi_3000

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [March 27, 2019, 4:18pm UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952/3 "2019-03-27T16:18:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [March 28, 2019, 4:25am UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952/4 "2019-03-28T04:25:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jxcwzk](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jxcwzk](https://discourse.codecombat.com/u/jxcwzk)\
**Post date:** [April 1, 2019, 5:12am UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952/5 "2019-04-01T05:12:56Z")

</div>

I was fainted and This level does afflict people

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [April 1, 2019, 7:39am UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952/6 "2019-04-01T07:39:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [April 22, 2019, 9:46pm UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952/7 "2019-04-22T21:46:58Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![jxcwzk](https://avatars.discourse-cdn.com/v4/letter/j/b9bd4f/32.png) [@jxcwzk](https://discourse.codecombat.com/u/jxcwzk)\
**Post date:** [April 25, 2019, 12:45pm UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952/8 "2019-04-25T12:45:39Z")

</div>

not yet…and i studying Raspberry Pi

---

<div class="post-metadata">

**Author:** ![brooksy125](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/brooksy125/32/9966_2.png) [@brooksy125](https://discourse.codecombat.com/u/brooksy125)\
**Post date:** [April 25, 2019, 2:04pm UTC](https://discourse.codecombat.com/t/polygonception-someone-can-help/17952/9 "2019-04-25T14:04:46Z")

</div>

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:

> **Spoiler linked to original code**
>
> In the line function.
> 
> ```python
> if distance < k / n + 1: # changed to < 10:
> # and
> fenxing = Vector.divide(side, n) # changed n to 5 since it is supposed to be a 5th of the size
> 
> ```

I’d be interested to see some other code to learn how to create a recursive with side length of 2.
