You are not logged in Log in Join
You are here: Home » Members » DaddyGravity » ContagiousFun » BookShelf » wikipage_view

Log in
Name

Password

 
 
FrontPage » ProgrammingForArtists » ContagiousScriptsLibrary »

BookShelf

'''Needs some work to be more general, but it draws a bookshelf, using the BoxBeam system as inspiration. My wife complained that she couldn't visualize what I was describing to her, so I whipped this up in about a half hour.'''

from visual import *

# all measurements in inches
two = 2 * 12
three = 3 * 12
four = 2 * two
five = 5 * 12
six = 2 * three
seven = 7 * 12
eight = 2 * four

gauge = 1.5
span = 4.5

class bar:
  def __init__(self, length=eight, pos=[0.0,0.0,0.0]):
    self.box = box(pos=pos,length=length, height=gauge, width=gauge)
    
class shelf:
  def __init__(self, width=3, height=two, length=eight):
    self.bars = []
    x = 0.0
    y = height
    z = 0.0
    for i in range(width):
      self.bars.append(bar(length=length, pos=(x,y,z)))
      z += span
    # two cross-bars
    x1 = length / 2 - gauge
    x2 = -x1
    y -= gauge
    w = width * 3 * gauge - gauge
    z = w / 2
    self.bars.append(box(pos=(x1,y,z),length=gauge, height=gauge, width=w))
    self.bars.append(box(pos=(x2,y,z),length=gauge, height=gauge, width=w))
      
class support:
  def __init__(self, length=eight, height=eight, width=3):
    self.members = []
    x1 = length / 2
    x2 = -x1
    y = height /2
    z1 = gauge
    z2 = span * (width - 1) + gauge
    self.members.append(box(height=height,pos=(x1,y,z1),length=gauge, width=gauge))
    self.members.append(box(height=height,pos=(x1,y,z2),length=gauge, width=gauge))
    self.members.append(box(height=height,pos=(x2,y,z2),length=gauge, width=gauge))
    self.members.append(box(height=height,pos=(x2,y,z1),length=gauge, width=gauge))
    
support()
shelf()
shelf(height=three)
shelf(height=four)
shelf(height=five)
shelf(height=six)
shelf(height=seven)
shelf(height=eight)