Drawing piled triangles in Python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Drawing piled triangles in Python (/thread-14463.html) |
Drawing piled triangles in Python - skkurt_cobain - Dec-01-2018 Hey everyone, I need to draw a pile of triangles that looks like this: I have written code that writes 3 triangles from left to right and one that makes 3 on top of each other, but I can't move on from there. Here are my codes: from turtle import Screen, Turtle from random import randint def repeat_triangle(t, l, n): setcolor(t, 1) #function I wrote for turtle and filled triangle being the same coloring for i in range(n): t.color(randint(0,255),randint(0,255),randint(0,255)) t.begin_fill() t.fd(100) t.lt(120) t.fd(100) t.lt(120) t.fd(100) t.lt(120) t.fd(100) otto.end_fill() def tiled_triangle(t, length): height = length * 3 ** 0.5 / 2 for _ in range(4): t.color(randint(0, 255), randint(0, 255), randint(0, 255)) t.begin_fill() for _ in range(3): t.fd(length) t.lt(120) t.end_fill() t.sety(t.ycor() + height) screen = Screen() screen.colormode(255) otto = Turtle('turtle') otto.penup() screen.mainloop() turtle.bye()Thanks in advance! I need this for a part of my homework for uni. Really thanks a lot! (I'm using Jupyter Notebooks so maybe there are some differences to regular Python, but I don't think any that matter.) RE: Drawing piled triangles in Python - woooee - Dec-01-2018 Use goto to position the Turtle at a new location. |