# The Honeycomb Challenge

Honeycomb is a structure of hexagonal cavities (cells of wax), made by bees to store honey and eggs.

In this challenge we will use a set of iterative algorithms to draw a honeycomb pattern.

First, we will create a function to draw a single hexagonal cavity. Our function called drawCavity() will take three parameters:

• x – the x coordinates to position the hexagon.
• y – the x coordinates to position the hexagon.
• edgeLength – the length in pixels of an edge of the hexagon.

We will then need to use some nested for loops in order to tessellate the hexagonal cell to recreate a 2D honeycomb pattern.

#### Python Code

We have started the code for you, using Python Turtle. You will need to complete this code further to complete the pattern fully.

[pms-restrict display_to=”not_logged_in” message=” “]

#### Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ message=” “]

#### Solution...

You are viewing this solution as part of your full membership subscription!

Python Code

#### Python Code

```#The honeycomb challenge
import turtle
myPen = turtle.Turtle()
myPen.shape("arrow")

myPen.color("#a86f14")
myPen.fillcolor("#efb456")
myPen.pensize(2)
myPen.tracer(0)
myPen.speed(0)

#A Procedue to draw a pentagonal cavity at a given (x,y) position.
def drawCavity(x,y,edgeLength):
myPen.penup()
myPen.goto(x,y)
myPen.pendown()
myPen.begin_fill()
for i in range(0,6):
myPen.forward(edgeLength)
myPen.left(60)
myPen.end_fill()

#Main Program Starts Here
#Comlpete this code to draw a full honeycomb pattern
for y in range(150,-150,-int(20*3**0.5)):
for x in range(-150,150,60):
drawCavity(x,y,20)
drawCavity(x+30,y-10*3**0.5,20)

myPen.hideturtle()
myPen.getscreen().update()
```
[/pms-restrict]

Did you like this challenge?

Click on a star to rate it!

Average rating 3.5 / 5. Vote count: 11

No votes so far! Be the first to rate this post.

As you found this challenge interesting...