I am trying to draw a fixed number of series of vertical stripes with random widths and colours. Unfortunately the kernel remains busy and nothing is drawn by the turtle.
I am using Anaconda - Jupyter I realise I am being quite vague but I genuinely don't have a clue how to tackle this. Really appreciate whoever takes their time to help!
import turtle
from turtle import *
import random
window = turtle.Screen()
window.colormode(255)
window.bgcolor("black")
turtle = turtle.Turtle()
turtle.speed(10)
turtle.penup()
turtle.shape("turtle")
turtle.goto(0,0)
#turtle.mode("standard")
def drawstripes(rgb, length, width):
turtle.color(rgb)
turtle.begin_fill()
turtle.forward(length)
turtle.left(90)
turtle.forward(width)
turtle.left(90)
turtle.forward(length)
turtle.end_fill()
n = 20
length = 100
totalwidth = 40
widths = [random.uniform(0, totalwidth) for i in range(0, n)]
widths.sort()
turtle.goto(0,length)
turtle.setheading(270)
while turtle.xcor() <= totalwidth :
for width in widths :
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
rgb = (r, g, b)
drawstripes(rgb, length, width)
As explained, expected result is a series of adjacent vertical stripes with different widths and colours, from x=0 to x=40px