Horje
Random Colored Shapes with python turtle Code Example
Random Colored Shapes with python turtle
# Random colored shapes 
from email.headerregistry import SingleAddressHeader
import turtle
import random

sc = turtle.Screen()
t = turtle.Turtle()
t.pensize(3)
t.pencolor("black")
t.speed(0)

# Create random shapes
def random_square(lenth, sides):
      for i in range(sides):
            t.fd(lenth)
            t.lt(360/sides)

def goto(x, y):
      t.up()
      t.goto(x, y)
      t.down()

for i in range(60):
      color = ["white", "green", "blue", "orange", "red", "purple","cyan"]
      t.pencolor(color[i % 7])
      random_square(random.randint(20, 60), random.randint(3, 8))
      goto(random.randint(-220, 220), random.randint(-220, 220))
      
      if t.pos()[0] >= 250 or t.pos()[0] <= -250:
            goto(t.pos()[0]-100, t.pos()[1]- 100)
            continue
      elif t.pos()[1] >= 250 or t.pos()[1] <= -250:
            goto(t.pos()[0]-100, t.pos()[1]- 100)
            continue

sc.exitonclick()




Python

Related
Python Docstrings Example Code Example Python Docstrings Example Code Example
configparser error reading relative file path Code Example configparser error reading relative file path Code Example
web socket in python Code Example web socket in python Code Example
pandas dataframe compare two dataframes and extract difference Code Example pandas dataframe compare two dataframes and extract difference Code Example
pyton get minimum value of array Code Example pyton get minimum value of array Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8