Here is the code I have for drawing a triangle and square in python tkinter canvas using create_lines, how would I use create_lines to create a pentagon and hexagon?
Note: For the pentagon and hexagon, the length and width refer to the total square shaped area the shape is contained within, not the width and length of the sides.
self.x, self.y = 50, 50
def triangle(self):
width = self.width.get()
length = self.length.get()
color = self.color_select.get()
self.canvas.create_line(self.x, self.y, (self.x + (int(length) / 2)), (self.y + int(length)), fill = color)
self.canvas.create_line(self.x, self.y, (self.x - (int(length) / 2)), (self.y + int(length)), fill = color)
self.canvas.create_line((self.x - (int(length) / 2)), (self.y + int(length)), (self.x + (int(length) / 2)), (self.y + int(length)), fill = color)
self.x += 50
def square(self):
width = self.width.get()
length = self.length.get()
color = self.color_select.get()
self.canvas.create_line(self.x, self.y, self.x + int(width), self.y, fill = color)
self.canvas.create_line(self.x, self.y, self.x, self.y + int(length), fill = color)
self.y += int(length)
self.canvas.create_line(self.x, self.y, self.x + int(width), self.y, fill = color)
self.x += int(width)
self.canvas.create_line(self.x, self.y, self.x, self.y - int(length), fill = color)
self.y -= int(length)
self.x += 50
def pentagon(self):
width = self.width.get()
length = self.length.get()
color = self.color_select.get()
def hexagon(self):
width = self.width.get()
length = self.length.get()
color = self.color_select.get()
math.sin()
,math.cos()
ormath.tan()
to calculate some distances. – furas