Dec-01-2018, 08:06 PM
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:
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.)