Skip to content

Instantly share code, notes, and snippets.

@encukou
Created October 6, 2021 09:28
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 encukou/35244d4300d825dc8ae0041b4f57374c to your computer and use it in GitHub Desktop.
Save encukou/35244d4300d825dc8ae0041b4f57374c to your computer and use it in GitHub Desktop.
# Generator for: https://youtu.be/xeL_Ifngcbo
# Save student code as obrazky/*.py and run this
import sys
import importlib
from pathlib import Path
import turtle
import time
import itertools
import dataclasses
import random
turtle.speed(0)
turtle.delay(0)
turtle.setup(1920, 1080)
# Monkeypatch turtle to disable functions unnecessary for "slideshow"
turtle.exitonclick = print
turtle.done = print
turtle.speed = lambda speed: None
# hotfix
_left = turtle.left
turtle.left = lambda angle: _left(angle % 360)
# Generator for randomized names
random.seed(1)
consonants = 'HKRDTNCJBFLMPSVZ'
vowels = 'AEIOU'
syllables = list(itertools.product(*(consonants, vowels)*3))
random.shuffle(syllables)
syllables = iter(syllables)
@dataclasses.dataclass
class Entry:
name: str
path: Path
code: object
entries = []
for path in sorted(Path('obrazky').glob('*.py')):
modcontent = path.read_text()
sig_line, _, _ = modcontent.partition('\n')
globs = {}
# Overcomplicated code to get author's name...
if sig_line.startswith('SIG'):
exec(sig_line, globs)
sig = globs.get('SIG')
if sig:
name = globs['SIG']
else:
name = f'Želví obrázek {"".join(next(syllables))}'
code = compile(modcontent, str(path), 'exec')
entries.append(Entry(
name,
path,
code,
))
for entry in entries:
print(entry.name, entry.path)
input('PRESS ENTER TO START...')
start = time.time()
for i in range(10):
random.shuffle(entries)
for entry in entries:
now = int(time.time() - start)
min, sec= divmod(now, 60)
print(f"{min:02}:{sec:02} {entry.name}")
turtle.title(entry.name)
turtle.reset()
turtle.speed(0)
turtle.shape('turtle')
turtle.bgcolor("white")
turtle.delay(2)
globs = {'print': lambda *a,**ka: None, '__file__': path.name}
exec(entry.code, globs)
time.sleep(1)
turtle.hideturtle()
time.sleep(1)
turtle.title('...')
turtle.title('…')
time.sleep(1)
print('------')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment