Hi guys, I'm stuck on this. I'm trying to draw 2 triangles in Turtle (not what you think).

I'm trying to get it to look like this:

Code:

forward(200)
left(120)
forward(200)
left(120)
forward(200)
right(120)

hideturtle()
done()

Any help is greatly appreciated!

## All 2 Replies

You can define a color with for example

``````fillcolor('green')
``````

Then you can fill a domain with

``````fill(True)
#... Here draw a domain as you did before
fill(False)
``````

You are better off drawing three triangles ...

``````''' turtle_triangle_up.py
use Python module turtle to draw a triangle pointing up
draw three triangles and fill with different colors
'''

import turtle as tu

tu.title("triangle up")

def triangle_up(x, y, side, color='black'):
"""
draw an equilateral triangle of size side starting at
coordinates x, y (lower right corner of triangle)
color is pen/fill color
"""
tu.up()  # pen up
tu.goto(x, y)
tu.down()  # pen down
tu.color(color)
tu.begin_fill()
for k in range(3):
tu.left(360/3)
tu.forward(side)
tu.end_fill()

# optional ...
# speeds from 1 to 10 enforce increasingly faster animation
tu.speed(speed=8)

# center is x=0, y=0
side = 250
x1 = 0
y1 = 0
triangle_up(x1, y1, side, 'red')
# use Pythagorean theorem to calculate offset
h = (side**2 - (0.5*side)**2)**0.5
w = ((0.5*side)**2 - (0.5*h)**2)**0.5
x2 = w
y2 = -h/2
triangle_up(x2, y2, side, '#00d900')  # mod-green
# now draw smaller yellow triangle
triangle_up(x1, y1, side/2, 'yellow')

# keep showing until window corner x is clicked
tu.done()
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.