1

I was just wondering on how to get different colors on each line of the hexagon. Below I have the desired output and input.

Output Right Now - Link to output right now

Output I want - Link to output I want

import turtle as trtl

colors = ["#9c2921", "#cf8e04","#f5d905",]

#--------------------
num_sides = int(input("Enter the number of sides(Enter 6 to get the output of the real image): "))

if num_sides == 6:
  print("Desired artwork is displayed")

side_length = 25
circumradius = side_length


angle = 360/len(colors)
trtl.width(10)



for color in colors:
    trtl.color(color)
    trtl.pensize(10)
    for move_turtle in range(1):
      trtl.penup()
      trtl.sety(-circumradius)
      trtl.pendown()
      trtl.circle(circumradius, steps = num_sides)

      circumradius *= 2

trtl.hideturtle()


  • 1
    You're drawing the shape in one call so it can only be one color. For separate colors, you need to draw each side separately. – Mike67 Sep 18 '20 at 00:04
  • The question is pretty similar to [this](https://stackoverflow.com/questions/63940734/drawing-radiating-circular-trapezoid-pattern-with-turtle/64379425#64379425) which you also asked. I'd recommend [accepting](https://stackoverflow.com/help/someone-answers) [cdlane's solution below](https://stackoverflow.com/a/63948817/6243352) if you wind up visiting Stack Overflow again. – ggorlen Oct 15 '20 at 21:25

1 Answers1

1

Oddly, your program looks like code I wrote in response to your previous question that has neither been accepted nor upvoted. Moving on:

Given this circle() and a fat pen based approach for drawing the hexagons, I believe this is about the best you can do:

import turtle
from itertools import cycle

COLORS = ["#9c2921", "#f5d905", "#cf8e04",]
NUM_SIDES = 6
SIDE_LENGTH = 50
PEN_WIDTH = 25

circumradius = SIDE_LENGTH

turtle.width(PEN_WIDTH)

color = cycle(COLORS)

for _ in range(4):

    turtle.penup()
    turtle.sety(-circumradius)
    turtle.pendown()

    for _ in range(NUM_SIDES):
        turtle.color(next(color))
        turtle.circle(circumradius, extent=360/NUM_SIDES, steps=1)

    circumradius += PEN_WIDTH*2

turtle.hideturtle()
turtle.done()

enter image description here

To get closer to the target image, you'd need to draw the individual segments of the hexagon (circle) as trapezoids.

import turtle
from itertools import cycle

COLORS = ["#9c2921", "#f5d905", "#cf8e04",]
NUM_SIDES = 6
SIDE_LENGTH = 50
PEN_WIDTH = 30

circumradius = SIDE_LENGTH

turtle.width(1)
turtle.speed('fastest')  # because I have no patience

color = cycle(COLORS)

for _ in range(4):

    turtle.penup()
    turtle.sety(-circumradius)
    turtle.pendown()

    for _ in range(NUM_SIDES):
        turtle.color(next(color))
        turtle.circle(circumradius, extent=360/NUM_SIDES, steps=1)
        turtle.right(90)

        turtle.begin_fill()
        turtle.forward(PEN_WIDTH/2)
        turtle.right(120)
        turtle.forward(circumradius + PEN_WIDTH/2)
        turtle.right(120)
        turtle.forward(PEN_WIDTH/2)
        turtle.end_fill()

        turtle.begin_fill()
        turtle.forward(PEN_WIDTH/2)
        turtle.right(60)
        turtle.forward(circumradius - PEN_WIDTH/2)
        turtle.right(60)
        turtle.forward(PEN_WIDTH/2)
        turtle.end_fill()

        turtle.left(90)

    circumradius += PEN_WIDTH*2

turtle.hideturtle()
turtle.done()

enter image description here

cdlane
  • 40,441
  • 5
  • 32
  • 81