from __future__ import division, print_function from visual import * # Default parameters def ikea(pos=(0, 0, 0), height=5, color=(1, 1, 1)): box(pos=pos, length=height*1.4, width=height*1.4, height=height/5, color=color) # Attempt #1: Works, but it's kind of a mess! # leg1_position = (pos[0] + height*0.6, pos[1], pos[2] + height*0.6) # cylinder(pos=leg1_position, axis=(0, -height, 0), radius=height/10, color=color) # lo stands for "leg offset" tx, ty, tz = pos lo = height*0.6 xlo = tx + lo nxlo = tx - lo zlo = tz + lo nzlo = tz - lo cylinder(pos=(xlo, ty, zlo), axis=(0, -height, 0), radius=height/10, color=color) cylinder(pos=(nxlo, ty, zlo), axis=(0, -height, 0), radius=height/10, color=color) cylinder(pos=(xlo, ty, nzlo), axis=(0, -height, 0), radius=height/10, color=color) cylinder(pos=(nxlo, ty, nzlo), axis=(0, -height*.95, 0), radius=height/10, color=color) ikea((0, 5, 0), 3, (1, 1, 1)) ikea((7,3, 0), 2, (1, 0, 0)) ikea((0, 7, 0), 2, (.3, .3, 1)) ikea((0, 8, 0), 1, (.3, 1, .3)) ikea((0, 8.6, 0), .6, (1, 1, .3)) ikea((0, 4, 0), 2, (1, .3, 1)) ikea() # Makes the default table