ScratchData LogoScratchData
Back to blob8108's profile

Cubes in Maya

BLblob8108•Created July 31, 2013
Cubes in Maya
51
42
1065 views
View on Scratch

Instructions

I was playing around with Maya, 3D graphics software, and I made this animation using Python in an hour or two. Maya has really good scripting: every time you perform a command from the UI, it writes a log telling you the scripting command for it. As usual, images imported into Scratch using Kurt: http://github.com/blob8108/kurt

Description

The Maya Python script I used: from maya import cmds from pprint import pprint import math import random SIZE = 10 DIRECTIONS = [] for x in (-1, 0, 1): DIRECTIONS.append((x, 0, 0)) for y in (-1, 0, 1): DIRECTIONS.append((0, y, 0)) for z in (-1, 0, 1): DIRECTIONS.append((0, 0, z)) def issafe(ax, ay, az): return (0 <= ax < SIZE and 0 <= ay < SIZE and 0 <= az < SIZE) # reset cmds.currentTime(0) for cube in cubes: try: cmds.delete(cube) except: pass # make cubes cubes = [] matrix = [[[0 for k in xrange(SIZE)] for j in xrange(SIZE)] for i in xrange(SIZE)] cubehistory = {} for x in range(0, SIZE): for y in range(0, SIZE): for z in range(0, SIZE): 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)] for t in range(0, 360, 24): 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: 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)

Project Details

Project ID11672264
CreatedJuly 31, 2013
Last ModifiedJuly 28, 2014
SharedJuly 31, 2013
Visibilityvisible
CommentsAllowed