Created
July 11, 2014 11:04
-
-
Save binweg/56f31bc915a82393d932 to your computer and use it in GitHub Desktop.
Source code for floor
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
DEBUG = True | |
max_frames = 120. | |
tiles = [] | |
def setup(): | |
size(400, 400, P3D) | |
smooth(8) | |
if DEBUG: | |
frameRate(100 / 3) | |
rectMode(CENTER) | |
tiles = [Tile(x, z) for x in range(-3, 4) for z in range(0, 20)] | |
fill(0xff, 0xff, 0xff) | |
def draw(): | |
background(0x0) | |
t = (frameCount - 1) / max_frames % 1 | |
translate(width / 2, height / 2) | |
# camera adjustments for more top-down view | |
rotateX(-HALF_PI / 4) | |
translate(0, -30, -20) | |
ambientLight(0xaa, 0xaa, 0xaa) | |
for i in range(3): | |
spotLight(0x22, 0x22, 0x22, | |
0, -50, 200 - 300 * i + 600 * t, | |
0, 1, 0, PI/4, 10) | |
directionalLight(0xff, 0xff, 0xff, -1, .1, -.5) | |
# minor camera wobble | |
translate(0, 0, 200) | |
rotateY(-.04 * cos(t * TWO_PI)) | |
translate(0, 0, -200) | |
translate(7 * sin(t * TWO_PI), 10 * cos(t * TWO_PI), 0) | |
for tile in tiles: | |
tile.draw(t) | |
if not DEBUG: | |
filter(BLUR, .5) | |
saveFrame('f###.gif') | |
if frameCount == max_frames: | |
exit() | |
class Tile(object): | |
def __init__(self, x_off=0, z_off=0): | |
self.x_off = x_off | |
self.z_off = z_off | |
self.t_fix = .6 + random(.15) + abs(x_off) * random(.03, .09) | |
self.ran_rot = random(1, 1.1) | |
self.ran_up = random(1, 3) | |
self.ran_side = random(.7, 2) | |
self.dir = 1 | |
if x_off < 0: | |
self.dir = -1 | |
elif x_off == 0 and random(1) < .5: | |
self.dir = -1 | |
def draw(self, t): | |
if (self.x_off + self.z_off) % 2: | |
ambient(0xf0, 0xf0, 0xf9) | |
else: | |
ambient(0xff, 0xff, 0xff) | |
t = (t + .05 * self.z_off) % 1 | |
pushMatrix() | |
translate(30 * self.x_off, 50, -350 + 600 * t) | |
if t < self.t_fix: | |
t_move = 1 - sin(map(t, 0, self.t_fix, 0, HALF_PI)) | |
translate(self.dir * 400 * t_move * self.ran_side, | |
-300 * t_move * self.ran_up, | |
-20 * self.z_off * t_move) | |
rotateX(.5 * self.ran_rot * t_move * HALF_PI) | |
rotateZ(self.dir * 1 * self.ran_rot * t_move * HALF_PI) | |
rotateY(self.dir * .3 * self.ran_rot * t_move * HALF_PI) | |
weight = constrain(map(self.t_fix - t, -.15, 0, 0, .3), 0, .3) | |
strokeWeight(weight) | |
rotateX(HALF_PI) | |
box(30, 30, 5) | |
popMatrix() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment