Created
May 11, 2016 18:31
-
-
Save iamevn/05d66ad2dd8c146491ed232e0d4217d5 to your computer and use it in GitHub Desktop.
copies lines to clipboard at end
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
##let's generate some fucking confetti | |
import random | |
from math import ceil, floor | |
## genconfetti() | |
## args: | |
# line template | |
# - needs to be formatted with start time, end time, color, x position, y position, frz, and drawing coordinates in that order with these keys | |
# times | |
# - array of times | |
# colors | |
# - array of colors | |
# shapes | |
# - array of shapes to use | |
# speedmin, speedmax | |
# - range for how many 2-frame steps a piece of confetti can take to fall across screen | |
# count | |
# - how many to generate | |
# resx, resy | |
# - screen width and height | |
# frz | |
# - if True, use random frz for each confetti piece | |
# fps | |
# - how many frames in a step of confetti animation | |
def genconfetti(line_template, times, colors, shapes, speedmin, speedmax, count, resx=1280, resy=720, frz=False, fps=2): | |
rotation = "" | |
framecount = len(times)-1 | |
s = "" | |
for n in range(count): | |
color = random.choice(colors) | |
speed = random.randrange(speedmin,speedmax+1) | |
# speed at which it drifts left or right | |
driftspeed = random.randrange(-1*floor(speedmax/2), ceil(speedmax/2)) | |
x = random.randrange(0, resx+1) | |
y = speed | |
framesneeded = ceil((resy/speed) * fps) | |
#f is starting frame number | |
#evenly distributed start time | |
#f = random.randrange(framecount - framesneeded) | |
#I want random samples from range [0, framecount-framesneeded) to be normally distributed | |
#maybe this is right? need to play with sigma more, maybe need to skew it | |
f = ceil(random.normalvariate((framecount - framesneeded)/2, (framecount - framesneeded)/2.5)) | |
if f < 0: | |
f = 0 | |
elif f > (framecount - framesneeded): | |
f = (framecount - framesneeded) | |
while (y <= resy and f+fps <= framecount): | |
if frz: | |
rotation = random.randrange(360) | |
s = s + "\n" + line_template.format(s=times[f], e=times[f+fps], c=color, x=x, y=y, frz=rotation, drawing=random.choice(shapes)) | |
#drift | |
x = x + driftspeed + random.randrange(-5, 5) | |
#fall | |
y = y + speed | |
#advance in frames | |
f = f+fps | |
return s | |
# stick string arg into clipboard | |
def toclipboard(s): | |
from tkinter import Tk | |
r = Tk() | |
r.withdraw() | |
r.clipboard_clear() | |
r.clipboard_append(s) | |
r.destroy() | |
if __name__ == '__main__': | |
random.seed() | |
line_template = """Dialogue: 9,{s},{e},confetti,,0,0,0,confetti,{{\c&H{c}&\\blur1\p1\pos({x},{y})\\frz{frz}}}{drawing}""" | |
#if we weren't using frz, leave "\frz" part out: | |
#line_template = """Dialogue: 0,{s},{e},confetti,,0,0,0,confetti,{{\c&H{c}&\blur1\p1\pos({x},{y}){frz}}}{drawing}""" | |
times = [ """0:04:10.48""", """0:04:10.52""", """0:04:10.56""", """0:04:10.60""", """0:04:10.64""", """0:04:10.68""", """0:04:10.73""", """0:04:10.77""", """0:04:10.81""", """0:04:10.85""", """0:04:10.89""", """0:04:10.93""", """0:04:10.98""", """0:04:11.02""", """0:04:11.06""", """0:04:11.10""", """0:04:11.14""", """0:04:11.18""", """0:04:11.23""", """0:04:11.27""", """0:04:11.31""", """0:04:11.35""", """0:04:11.39""", """0:04:11.43""", """0:04:11.48""", """0:04:11.52""", """0:04:11.56""", """0:04:11.60""", """0:04:11.64""", """0:04:11.68""", """0:04:11.73""", """0:04:11.77""", """0:04:11.81""", """0:04:11.85""", """0:04:11.89""", """0:04:11.93""", """0:04:11.98""", """0:04:12.02""", """0:04:12.06""", """0:04:12.10""", """0:04:12.14""", """0:04:12.19""", """0:04:12.23""", """0:04:12.27""", """0:04:12.31""", """0:04:12.35""", """0:04:12.39""", """0:04:12.44""", """0:04:12.48""", """0:04:12.52""", """0:04:12.56""", """0:04:12.60""", """0:04:12.64""", """0:04:12.69""", """0:04:12.73""", """0:04:12.77""", """0:04:12.81""", """0:04:12.85""", """0:04:12.89""", """0:04:12.94""", """0:04:12.98""", """0:04:13.02""", """0:04:13.06""", """0:04:13.10""", """0:04:13.14""", """0:04:13.19""", """0:04:13.23""", """0:04:13.27""", """0:04:13.31""", """0:04:13.35""", """0:04:13.39""", """0:04:13.44""" ] | |
colors = [ """HAEFFE4""", """HFEAEEE""", """HFDB0AE""" ] | |
shapes = [ """m -21 4 l 9 -27 l 29 -6 b 19 0 14 9 9 19""", """m -9 21 b 2 28 8 30 12 35 b 7 11 9 -8 8 -25 b -3 -21 -11 -22 -12 -24""", """m -5 -19 b 6 -12 11 -5 16 4 b 11 9 8 15 5 25 b 0 16 -1 7 -14 8""", """m -14 23 b -9 24 -5 24 0 25 b 10 11 12 -1 13 -17 b 7 -18 0 -20 -7 -22 b -5 -8 -8 9 -14 23""", """m -14 19 b -15 2 -14 -16 -17 -22 b -9 -23 6 -25 16 -22 b 19 -6 19 6 11 20""", """m -16 23 b 2 28 8 30 22 27 b 11 11 9 -8 9 -25 b -3 -21 -11 -22 -21 -21""", """m -17 -14 b -17 -14 -17 -14 -17 -14 b -2 -9 11 -16 27 -12 b 21 0 21 13 20 26 b 9 16 -7 23 -22 16""", """m -9 29 b 2 28 5 26 9 20 b 7 11 2 -8 5 -23 b -2 -22 -9 -25 -12 -24""", """m -23 -6 b -10 -2 11 -3 25 -6 b 24 -3 26 6 26 13 b 6 16 -7 7 -31 14""", """m -25 -1 b -14 -5 11 -3 30 0 b 26 1 26 6 20 13 b 7 10 -7 7 -21 12""" ] | |
speedmin = 25 #todo: find lower-bound from how many frames there are and how much ground needs to be covered | |
speedmax = 80 | |
count = 80 | |
s = genconfetti(line_template, times, colors, shapes, speedmin, speedmax, count, frz=True) | |
#print(s) | |
toclipboard(s) | |
print("{} lines copied to clipboard".format(len(s.splitlines()))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd have rather written this in lua as an aegisub script, but I don't have an interpreter installed on this computer and am really lazy