Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to make random colors in python turtle

import turtle, random
colors = ["green","brown"]
theColor = random.choice(colors)
turtle.color(theColor)
Comment

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()
Comment

PREVIOUS NEXT
Code Example
Python :: sorted multiple keys python 
Python :: elif python 
Python :: docker remote 
Python :: django create multiple objects 
Python :: Accessing of Tuples in python 
Python :: web scraping with selenium 
Python :: python types 
Python :: join function in python 
Python :: is login a class in python 
Python :: how to store the variable in dictionary 
Python :: add header info in django response 
Python :: Python NumPy delete Function Example Deletion from 1D array 
Python :: heroku how to access config vars django 
Python :: how to import somthing from another directory in pyhon 
Python :: Dynamic Form Fields Django 
Python :: __all__ python 
Python :: f string python 
Python :: length of queue python 
Python :: python keyword arguments 
Python :: python variables and data types 
Python :: polls/models.py 
Python :: pyhton serialize object 
Python :: KeyError 
Python :: python list extend 
Python :: python package install 
Python :: for _ in range() in python 
Python :: python clear() 
Python :: python decimal 
Python :: drop variable pandas 
Python :: “Python unittest Framework 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =