Created
June 29, 2015 01:52
-
-
Save anonymous/11661b93e4625f78a5ac to your computer and use it in GitHub Desktop.
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 python | |
""" | |
RECORD_DIR=/tmp/part01/ python main.py | |
ffmpeg -y -framerate 25 -i '/tmp/part01/%04d.png' -i 1xedit_final.wav -c:v libx264 -pix_fmt yuv420p -crf 23 -c:a aac -strict experimental -b:a 192k /tmp/part01/out.mp4 | |
""" | |
import math, pygame, os, time, colorsys, sys | |
from pygame.locals import * | |
import pygame.draw, pygame.image | |
#constants | |
WINSIZE = [ 800, 800] | |
CENTER = map(lambda x: x/2, WINSIZE) | |
RADIUS = WINSIZE[0] / 2 - 2 | |
def circle_point(mod, point, radius = RADIUS): | |
angle = ((point % mod) * 360 / float(mod)) * math.pi / 180.0 | |
return int(CENTER[0] + radius * math.sin(angle)), int(CENTER[1] + radius * math.cos(angle)) | |
def square_point(mod, point, radius = RADIUS): | |
angle = ((point % mod) * 360 / float(mod)) * math.pi / 180.0 | |
radius = abs(400 / math.cos(angle))# + math.pi) % (math.pi/4.0))) | |
return int(CENTER[0] + radius * math.sin(angle)), int(CENTER[1] + radius * math.cos(angle)) | |
def draw_msg(msg): | |
text = font.render(msg, True, (180, 180, 255)) | |
screen.blit(text, (5, 770)) | |
class CircleRender: | |
def __init__(self, mod, start_mult, step, hue = 0.4): | |
self.mod = mod | |
self.mult = start_mult | |
self.step = step | |
self.hue = hue | |
def draw(self, frame): | |
for j in xrange(1, self.mod): | |
s = circle_point(self.mod, j) | |
d = circle_point(self.mod, j * self.mult) | |
hue = self.hue + (j % 100) / 300.0 | |
sat = 0.5 | |
val = 0.2 + j / (float(self.mod)*1.5) | |
color = map(lambda x: x*255, colorsys.hsv_to_rgb(hue, 0.5, 0.2 + j / (float(self.mod)*1.5))) | |
pygame.draw.line(screen, color, s, d, 1) | |
self.mult += self.step | |
class StepRender: | |
def __init__(self): | |
self.mod = 67 * 2 - 2 | |
self.mult = 3 | |
self.pos = 2 | |
def draw(self, frame): | |
for j in range(1, self.pos) + range(self.mod - self.pos, self.mod): | |
s = circle_point(self.mod, j) | |
d = circle_point(self.mod, j * self.mult) | |
hue = 0.6 + (j % 100) / 500.0 | |
sat = 0.5 | |
val = 0.2 + j / (float(self.mod)*1.5) | |
color = map(lambda x: x*255, colorsys.hsv_to_rgb(hue, 0.5, 0.2 + j / (float(self.mod)*1.5))) | |
pygame.draw.line(screen, color, s, d, 1) | |
if self.pos >= (self.mod / 2 + 4): | |
self.pos = 1 | |
self.mult += 1 | |
self.pos += 1 | |
class SquareRender: | |
def __init__(self): | |
self.mod = 337 | |
self.mult = 1.5 | |
self.step = 0.05 | |
self.hue = 0.1 | |
def draw(self, frame): | |
for j in xrange(1, self.mod): | |
s = square_point(self.mod, j) | |
d = square_point(self.mod, j * self.mult) | |
hue = self.hue + (j % 100) / 300.0 | |
sat = 0.5 | |
val = 0.2 + j / (float(self.mod)*1.5) | |
color = map(lambda x: x*255, colorsys.hsv_to_rgb(hue, 0.5, 0.2 + j / (float(self.mod)*1.5))) | |
pygame.draw.line(screen, color, s, d, 1) | |
self.mult += self.step | |
scenes = [ | |
(2650, SquareRender()), | |
(2150, CircleRender(701, 80, -0.04, hue = 0.2)), | |
#(1650, CircleRender(251, 0, 0.01)), | |
(1650, CircleRender(701, 70, 0.02, hue = 0.2)), | |
(1375, StepRender()), # 1437 | |
(875, CircleRender(701, 48, 0.02, hue = 0.5)), | |
(625, CircleRender(251, 25, 0.08)), | |
(0, CircleRender(251, 0, 0.04)), | |
] | |
clock = pygame.time.Clock() | |
pygame.init() | |
screen = pygame.display.set_mode(WINSIZE) | |
font = pygame.font.SysFont(u'dejavusansmono', 12) | |
frame = int(os.environ.setdefault('START_FRAME', "0")) | |
max_frame = int(os.environ.setdefault("END_FRAME", "2950")) | |
while True: | |
screen.fill((0, 0, 0)) | |
for sframe, scene in scenes: | |
if frame >= sframe: | |
break | |
draw_msg("%04d: Mod %d, Mult %.2f" % (frame, scene.mod, scene.mult)) | |
scene.draw(frame) | |
pygame.display.update() | |
if "RECORD_DIR" in os.environ: | |
dname = os.environ['RECORD_DIR'] | |
try: | |
os.mkdir(dname) | |
except: | |
pass | |
fname = "%s/%04d.png" % (dname, frame) | |
try: | |
pygame.image.save(screen, fname) | |
except Exception, e: | |
print fname, e | |
raise | |
if frame >= max_frame: | |
exit(0) | |
frame += 1 | |
clock.tick(25) | |
for e in pygame.event.get(): | |
if e.type == QUIT or (e.type == KEYUP and e.key == K_ESCAPE): | |
exit(0) | |
if "--debug" in sys.argv: | |
raw_input("press next") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment