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 :: pytorch use multiple gpu 
Python :: remove outliers in dataframe 
Python :: openpyxl xls 
Python :: pip install specific version 
Python :: real time crypto prices python 
Python :: numpy create a matrix of certain value 
Python :: psyche 
Python :: python get system information 
Python :: pandas iterate columns 
Python :: tkinter window background color 
Python :: pandas convert date to quarter 
Python :: TinyDB 
Python :: make calculator in python 
Python :: pyAudioAnalysis 
Python :: how to open sound file in python 
Python :: on click on image pygame 
Python :: python lexicographical comparison 
Python :: install hydra python 
Python :: __gt__ 
Python :: How do you find the missing number in a given integer array of 1 to 100? 
Python :: right angle triangle in python 
Python :: selectfield flask wtf 
Python :: where to import kivy builder 
Python :: merge two dataframes with common columns 
Python :: how to compare two text files in python 
Python :: fyit download 
Python :: python convert dictionary to pandas dataframe 
Python :: python catch multiple exceptions 
Python :: show image python 
Python :: pandas convert multiple columns to categorical 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =