Write a function named triangle that use the turtle graphic library to draw triangle. The functions should take arguments for the X and Y coordinates of the triangle’s vertices, and color with which the triangle should be filled. Demonstrate the function in a program.

Respuesta :

Answer:

import turtle

def drawTriangle(p1=(0,0), p2=(100,0), p3=(0,100), color=(0,0,255)):

'''

This function draws a filled triangle between

points p1, p2 and p3.

Default points are (0,0),(100,0),(0,100) and

default color(r,g,b) is blue.

'''

t= turtle.Turtle() #initialize turtle

t.color(color) #set color of lines

t.fillcolor(color) #set fill-color for closed drawings

t.penup()

t.goto(p1) #start from p1

t.begin_fill() #start color fill

t.pendown()

t.goto(p2) #move to p2

t.goto(p3) #move to p3

t.goto(p1) #back to p1

t.end_fill() #end color fill

drawTriangle((50,50), (0,50), (50,0), (255,0,0))

turtle.done()

RELAXING NOICE
Relax