Skip to content

Instantly share code, notes, and snippets.

@wanieldilson
Created November 9, 2022 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wanieldilson/4056e3e05466b1d3c57d3117c7d1fb89 to your computer and use it in GitHub Desktop.
Save wanieldilson/4056e3e05466b1d3c57d3117c7d1fb89 to your computer and use it in GitHub Desktop.
Turtle Graphics testing as part of 100 days of code
import turtle
from turtle import Turtle, Screen, colormode
import random
turtle.colormode(255)
jim = Turtle()
jim.shape("turtle")
jim.color("DarkOliveGreen")
jim.speed("fastest")
colours = ["aquamarine2", "bisque2", "BlueViolet", "red", "coral", "yellow", "DarkGray", "DarkOrange1", "FireBrick",
"gold", "LawnGreen", "bisque3", "red", "yellow"]
turns = [0, 90, 180, 270]
def draw_square():
for _ in range(4):
jim.forward(100)
jim.right(90)
def draw_dashed_line():
for _ in range(10):
jim.forward(10)
jim.penup()
jim.forward(10)
jim.pendown()
def draw_shapes(sides):
for _ in range(sides):
jim.forward(100)
jim.right(360 / sides)
def draw_circle(sides):
for _ in range(sides):
jim.forward(1)
jim.right(360 / sides)
def shape_drawer():
for _ in range(3, 12):
jim.pencolor(random.choice(colours))
draw_shapes(_)
def random_colour():
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
rgb = (r, g, b)
return rgb
def random_walk(distance):
jim.pensize(5)
jim.speed(10)
for _ in range(distance):
jim.pencolor(random_colour())
jim.forward(30)
jim.setheading(random.choice(turns))
def spirograph(circles):
for _ in range(circles):
jim.pencolor(random_colour())
jim.circle(100)
jim.setheading(_ * (360 / (circles - 1)))
spirograph(80)
screen = Screen()
screen.exitonclick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment