Skip to content

Instantly share code, notes, and snippets.

@jasonamyers
Created April 26, 2019 01:58
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 jasonamyers/3c674be27f2ad7dbc14aa041a0e9b8b8 to your computer and use it in GitHub Desktop.
Save jasonamyers/3c674be27f2ad7dbc14aa041a0e9b8b8 to your computer and use it in GitHub Desktop.
Built Sponsor toy
import turtle
from random import randint, randrange
import tkinter as _
_.ROUND = _.BUTT
SCALE = 5
turtle.speed(0)
turtle.colormode(255)
turtle.bgcolor('black')
built = turtle.Turtle(visible=False)
built.speed(0)
#### Draw Sky ####
def draw_star(x, y, side):
built.color(randint(0, 255), randint(0, 255), randint(0, 255))
built.begin_fill()
built.penup()
built.goto(x, y)
built.pendown()
for _ in range(5):
built.forward(side)
built.right(144)
built.forward(side)
built.end_fill()
def random_length():
return randrange(5, 25)
def random_xy_coord():
return randrange(-290, 290), randrange(-270, 270)
stars = 20
for k in range(stars):
side = random_length() # length of side
x, y = random_xy_coord()
draw_star(x, y, side)
#### Draw spirograph squares ####
def draw_spiro():
x = 1
while x < 100:
r = randint(0, 255)
g = randint(0, 255)
b = randint(0, 255)
built.pencolor(r, g, b)
built.fd(50 + x)
built.rt(90.991)
x = x + 1
draw_spiro()
built.reset()
#### Draw Honeycomb ####
built.speed(0)
SIZE = 15
CIRCLES = 2
def move(length, angle):
built.right(angle)
built.forward(length)
def draw_hex():
built.pendown()
built.color(randint(0, 255), randint(0, 255), randint(0, 255))
built.begin_fill()
for i in range(6):
move(SIZE, -60)
built.end_fill()
built.penup()
# start
built.reset()
built.penup()
for circle in range(CIRCLES):
if circle == 0:
draw_hex()
move(SIZE, -60)
move(SIZE, -60)
move(SIZE, -60)
move(0, 180)
for i in range(6):
move(0, 60)
for j in range(circle + 1):
draw_hex()
move(SIZE, -60)
move(SIZE, 60)
move(-SIZE, 0)
move(-SIZE, 60)
move(SIZE, -120)
move(0, 60)
#### Built Logo ####
built.reset()
screen = turtle.Screen()
width, height = screen.window_width() / SCALE, screen.window_height() / SCALE
screen.setworldcoordinates(-width//2, -height//2, width//2, height//2)
built.speed(0)
built.width(SCALE)
frame = [
"::::: :: ++++++ +++++ +++++ +++++ ",
"::::: ::::::: ++++++ +++++ +++++ +++++ ",
":::::::::::::::::::: ++++++ +++++ ++++++++++",
"::::::::::::::::::::::: +++++++++++++ +++++ +++++ +++++ +++++ ++++++++++",
":::::::::: ::::::::::: +++++++++++++++++ +++++ +++++ +++++ +++++ ++++++++++",
"::::::: ::::::: ++++++++++++++++++ +++++ +++++ +++++ +++++ +++++ ",
"::::: :: ::::: ++++++ +++++++ +++++ +++++ +++++ +++++ +++++ ",
"::::: ::::::: ::::: ++++++ ++++++ +++++ +++++ +++++ +++++ +++++ ",
"::::: :::::::::::: ::::: ++++++ +++++ +++++ +++++ +++++ +++++ +++++ ",
"::::::::::::::::::::::::: ++++++ ++++++ ++++++ ++++++ +++++ +++++ +++++ ",
":::::::::: ::::::::::: ++++++++++++++++++ +++++++++++++++++ +++++ +++++ ++++++++ ",
"::::::: ::::::: +++++++++++++++++ +++++++++++++++ +++++ +++++ ++++++++ ",
"::: :::: +++++++++++++++ +++++++++++ +++++ +++++ +++++++ "
]
colors = {
"+": "white",
" ": "black",
":": "red"
}
for row in frame:
built.pendown()
for symbol in row:
built.pencolor(colors.get(symbol, 'white'))
built.forward(1)
built.penup()
built.backward(len(row))
built.right(90)
built.forward(1)
built.left(90)
turtle.exitonclick()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment