
xxxxxxxxxx
#Confetti Challenge - www.101computing.net/confetti-challenge/
import turtle
import random
numberOfConfetti = 50
myPen = turtle.Turtle()
myPen.hideturtle()
myPen.speed(0)
window = turtle.Screen()
window.bgcolor("#000000")
#Draw the Canvas
myPen.penup()
myPen.goto(-180,-182)
myPen.pensize(4)
myPen.color("#FF00FF")
myPen.pendown()
for side in range(0,4):
myPen.forward(360)
myPen.left(90)
myPen.pensize(1)
radius = 18 #Radius of a confetti, in pixels
list = []
#Add Confetti
for confetti in range(0,numberOfConfetti):
overlap = True
while overlap:
x = random.randint(-180+radius,180-radius)
y = random.randint(-180+radius,180-radius)
#Check if new confetti overlap with any existing confetti
overlap = False
for confetti in list:
#Use Pythagoras Formula to calculate the distance between two confetti
distance = ((confetti[0] - x)**2 + (confetti[1] - y)**2)**0.5
#If two confetti are too close to each other, then they will overlap!
if distance<=(2*radius) + 2:
overlap = True
list.append([x,y])
#Generate a random purple colour!
color = (random.randint(50,255),0,random.randint(50,255))
myPen.penup()
myPen.goto(x,y-radius)
myPen.pendown()
myPen.fillcolor(color)
myPen.color(color)
myPen.begin_fill()
myPen.circle(radius-2)
myPen.end_fill()
print(str(len(list)) + " confetti")
print("The end")
task_alt