ScratchData LogoScratchData
Back to blob8108's profile

Cubes in Maya, #2

BLblob8108•Created August 1, 2013
Cubes in Maya, #2
25
15
428 views
View on Scratch

Instructions

Same as the last project, but with the script reversed and building inward rather than just shuffling cubes. The lighting's different, too. --- I was playing around with Maya, 3D graphics software, and I made this animation using Python in an hour or two.

Description

The Maya Python script I used: from maya import cmds from pprint import pprint import math import random X_SIZE = 50 Y_SIZE = 50 Z_SIZE = 50 DIRECTIONS = [ (0, 0, 0), (1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1), ] def issafe(ax, ay, az): return (0 <= ax < X_SIZE and 0 <= ay < Y_SIZE and 0 <= az < Z_SIZE) # reset cmds.currentTime(0) for cube in cubes: try: cmds.delete(cube) except: pass # make cubes cubes = [] matrix = [[[0 for k in xrange(Z_SIZE)] for j in xrange(Y_SIZE)] for i in xrange(X_SIZE)] cubehistory = {} for x in range(20, 25): for y in range(20, 25): for z in range(20, 25): #if random.random() < 0.7: cube = cmds.polyCube()[0] cmds.move(x, y, z, cube) cubes.append(cube) matrix[x][y][z] = 1 cubehistory[cube] = [(x, y, z)] END = 20 * 6 cmds.currentTime(END + 6) cmds.setKeyframe(cubes) prob = 0.01 for t in range(END, 0, -6): #prob = (1 - (t / END)) * 0.05 vacate_positions = [] cmds.currentTime(t) for cube in cubes: (x, y, z) = map(int, cmds.objectCenter(cube)) assert matrix[x][y][z] == 1 random.shuffle(DIRECTIONS) for (dx, dy, dz) in DIRECTIONS: (nx, ny, nz) = (x + dx, y + dy, z + dz) if issafe(nx, ny, nz) and not (nx, ny, nz) in cubehistory[cube]: if matrix[nx][ny][nz] == 0: if random.random() < prob: vacate_positions.append((x, y, z)) matrix[nx][ny][nz] = 1 cmds.move(nx, ny, nz, cube) cubehistory[cube].append((nx, ny, nz)) for (x, y, z) in vacate_positions: matrix[x][y][z] = 0 cmds.setKeyframe(cubes) prob *= 1.4 print prob cmds.select(cubes)

Project Details

Project ID11686321
CreatedAugust 1, 2013
Last ModifiedAugust 1, 2013
SharedAugust 1, 2013
Visibilityvisible
CommentsAllowed