Hello world!

Welcome to Sites At Penn State. This is my first post for the Metabolism Project I did during the computer programming course. Thank you for visiting my site!

For this project, I used what I have learned in class to recreate the Nakagin Capsule Tower designed by Japanese architect Kisho Kurokawa. The Nakagin Capsule Tower is an example of the Japanese Metabolism, which was a post-war Japanese architectural movement that fused ideas about architectural mega structures with those of organic biological growth (https://en.wikipedia.org/wiki/Metabolism_(architecture)).

Please feel free to search through the site!

Capstone Project – Recreating Nakagin Capsule Tower with Computer Programming

This is the final Capstone Project  for which we have completed various exercises during the semester. My capstone project is to create metabolism architecture by recreating the Nakagin Capsule Tower.

Here is the Python Code:


import rhinoscriptsyntax as rs
import random as r

rs.DeleteObjects (rs.AllObjects ())
#number of capsules I want in XYZ directions
nrCapsulesX = 4
nrCapsulesY = 2
nrCapsulesH = rs.GetInteger ("How many floors for building 1?",8)

nrCapsulesX2 = 4
nrCapsulesY2 = 2
nrCapsulesH2 = rs.GetInteger ("How many floors for building 2?",10)

Probability = rs.GetReal ("How many capsules should be mirrored?", .8, 0, 1)

#capsule dimension: 2.5m x 4m x 2.5m, window: 1.3m diameter
#In feet:           8.2ft x 13.1ft x 8.2ft    4.4 ft
CapsuleSizeX = 8.2
CapsuleSizeY = 13.1
CapsuleSizeH = 8.2

#Base dimension: 20 x 99 x 40 x 119 x 60
#Core size: 19.8 ft 
#                   x X(the X equals to two times of the X of capsules so they touch each other) 
#                   x H(the H will change according to how many floors the building has)
CoreSizeX = 16.4
CoreSizeY = 2*CapsuleSizeX
CoreSizeH = nrCapsulesH*CapsuleSizeH+40
CoreSizeH2 = nrCapsulesH2*CapsuleSizeH+40
#wall thickness & floor thickness
offsetDist = 1.2
thickness = offsetDist

#sphere diameter(window) 1.3 meters - 4.4 ft - raius 2.2 ft
radius = 2.2

#distance from the second building
mygap = 33

#height difference between the two building.
DifHeight = CoreSizeH2-CoreSizeH

#we need to define the workplane before create a rectangle.
plane = rs.WorldXYPlane ()
#make the base.
B = rs.AddPolyline (([-22,12,12], [-6,30,12], [75,30,12], [90,0,12], [8,-35,12], [-22,12,12]))
Base = rs.ExtrudeCurveStraight (B,[0,0,0], [0,0,12.6])
#make base columns.
#ColumnPtsBase = [[-18,12,0],[-4,24,0],[73,24,0],[86,0,0],[5,-31,0]]
#ColumnPtsTop = [[-18,12,12],[-4,24,12],[73,24,12],[86,0,12],[5,-31,12]]
Column1 = rs.AddCylinder ([-18,12,0],[-18,12,12],2,True)
Column2 = rs.AddCylinder ([3,26,0],[3,26,12],2,True)
Column2a = rs.CopyObject (Column2,[17.5,0,0])
Column2b = rs.CopyObject (Column2,[35,0,0])
Column2c = rs.CopyObject (Column2,[52.5,0,0])
Column3 = rs.AddCylinder ([73,24,0],[73,24,12],2,True)
Column4 = rs.AddCylinder ([86,2,0],[86,2,12],2,True)
Column4a = rs.CopyObject (Column4,[-13,0,0])
Column4b = rs.CopyObject (Column4,[-30,-12,0])
Column4c = rs.CopyObject (Column4,[-48,-20,0])
Column4d = rs.CopyObject (Column4,[-66,-20,0])
Column5 = rs.AddCylinder ([3,-18,0],[3,-18,12],2,True)

#make the core.
C = rs.AddRectangle (plane, CoreSizeX, CoreSizeY)
Core1 = rs.ExtrudeCurveStraight (C, [0,0,0], [0,0,CoreSizeH])
rs.CapPlanarHoles (Base)
rs.CapPlanarHoles (Core1)
#find the corner points of the core, so that I can use two diagonal ones to define the mirror axis.
Cps = rs.BoundingBox (Core1)
Cp1 = Cps[0]
Cp2 = Cps[2]
Cp3 = Cps[1]
Cp4 = Cps[3]
#copy to a second core.
C2 = rs.ExtrudeCurveStraight (C, [0,0,0], [0,0,CoreSizeH2])
rs.CapPlanarHoles (C2)
Core2 = rs.MoveObject (C2,[mygap,0,0])
Cps2 = rs.BoundingBox (Core2)
Cp5 = Cps2[0]
Cp6 = Cps2[2]
Cp7 = Cps2[1]
Cp8 = Cps2[3]


#create the top pf the building.
topPlan = rs.MoveObject (C,[0,0,CoreSizeH] )
top = rs.ExtrudeCurveStraight (topPlan, [0,0,0], [0,0,15])
rs.CapPlanarHoles (top)
#after creating a box, I find its corner points by boundingbox.
Btop = rs.BoundingBox (top)

#make a general definition of midpoint so I can use it several times.
def midpoint (Pa,Pb):
    midpoint = [Pa[0]+(Pb[0]-Pa[0])/2, Pa[1]+(Pb[1]-Pa[1])/2, Pa[2]+(Pb[2]-Pa[2])/2]
    return midpoint
mid1 = midpoint (Btop[2],Btop[6])
mid2 = midpoint (Btop[0],Btop[4])


#create the top part of the core.
#use the midpoint function to find midpoints of the cube so to create a slanted surface.
SP = rs.AddPolyline ((Btop[3],mid1, Btop[5], mid2, Btop[3]))
SlantPlane = rs.AddPlanarSrf (SP)
#use the slanted surface to split the top part and delete the unwanted part.
CutTopinfo = rs.SplitBrep (top, SlantPlane)
rs.DeleteObject (top)
CutTop = CutTopinfo [0]
rs.DeleteObject (CutTopinfo [1])
#copy it to the second building and make it capable of moving as the height of the second building changes.
CT = rs.CopyObject (CutTop,[mygap,0,0])
CutTop2 = rs.MoveObject (CT,[0,0,DifHeight])
rs.CapPlanarHoles (CutTop2)


#use definition function to define the capsule objects.
#the plan in the functions will be the reactangles created later at the locations of the capsules.
def makeCapsule (plan, CapsuleHeight):
    #find the origin point of the plan to find the middle point of the plan and ceiling point.
    origin = rs.CurveStartPoint (plan)
    midPoint = [origin[0] + CapsuleSizeX / 2, origin[1] + CapsuleSizeY / 2, 0]
    ceiling = [origin[0] +  CapsuleSizeX / 2, origin[1] + CapsuleSizeY / 2, CapsuleHeight]
    #make exterior facade of the wall of the capsules.
    facade = rs.ExtrudeCurveStraight (plan, midPoint,ceiling)
    #offset the plan to find the inner facades of the walls.
    innerplan = rs.OffsetCurve (plan, midPoint, offsetDist)
    innerFacade = rs.ExtrudeCurveStraight (innerplan, midPoint, ceiling)
    #close the gap between exterior facade and the inner facade.
    bottomFacade = rs.AddLoftSrf ([plan, innerplan])
    topFacade = rs.CopyObject (bottomFacade, (0,0,CapsuleHeight))
    #explode the facade and fine the one that will have the window on it.
    facade2 = rs.ExplodePolysurfaces (facade, False)
    wall = facade2[1]
    #join the exterior and inner facades to make the wall of capsules.
    thickWall = rs.JoinSurfaces ([facade, innerFacade, bottomFacade, topFacade], True)
    #find the center point of the wall so to create a sphere on it.
    #then extract the sphere from the wall and leave the window hole.
    point = rs.SurfaceAreaCentroid (wall)[0]
    sphere = rs.AddSphere (point, radius)
    openWall = rs.BooleanDifference (thickWall, sphere)
    #delete the exploded facades.
    rs.DeleteObjects (facade2)
    #make floor and ceiling from the plan.
    floor = rs.ExtrudeCurveStraight (plan, [0,0,0], [0,0,thickness])
    floorSlab = rs.CapPlanarHoles (floor)
    ceiling = rs.CopyObject (floor, (0, 0, CapsuleHeight - thickness))
    #join all the wall, floor and ceiling together to gert the wanted capsule.
    Capsule = rs.BooleanUnion ([openWall, floor, ceiling])
    rs.DeleteObjects (plan)
    rs.DeleteObjects (innerplan)
    return Capsule[0]

Crv = []
def makebuilding (gap, core, nrH):
    #Use three "for" loops, one inside another, to define the location of each capsule.
    #Under each "for" loop, append the created objects into a list, 
    #so that I would get capsules in a "row", a "floor", and the whole "building".
    Cps = rs.BoundingBox (core)
    Cp1 = Cps[0]
    Cp2 = Cps[2]
    Cp3 = Cps[1]
    Cp4 = Cps[3]

    Building = []
    #creates another unstructured list for all the capsules, so that I can use it to make changes only to the capsules.
    Allcapsules = []
    for h in range (0, nrH):
        Floor = []
        for y in range (0, nrCapsulesY):
            Row = []
            for x in range (0, nrCapsulesX):
                #we need to move the workplane so that to crate a new rectangle at the new place.
                #Find the location of all the capsules.
                newPlane = rs.MovePlane (plane, [x*CapsuleSizeX-CapsuleSizeX+gap,y*CapsuleSizeY-CapsuleSizeY/2,h*CapsuleSizeH+24.6])
                newCapsule = rs.AddRectangle (newPlane, CapsuleSizeX, CapsuleSizeY)
                #append the created rectangles into a list and I will delete them at the end.
                Crv.append (newCapsule)
                #make the block with the defined makeBlock function.
                CAPSULE = makeCapsule (newCapsule, CapsuleSizeH)
                Row.append (CAPSULE)
                Allcapsules.append (CAPSULE)
                #find the location of the capsules again so to use them again.
                MovePlane = rs.MovePlane (plane, [x*CapsuleSizeX-CapsuleSizeX+gap,y*CapsuleSizeY-CapsuleSizeY/2,h*CapsuleSizeH+24.6])
                RotatePlane = rs.AddRectangle (MovePlane, CapsuleSizeX, CapsuleSizeY)
                #make rectangles at the locations and make planar surfaces so that to find the center points which will be used to rotate the blocks.
                pl = rs.AddPlanarSrf (RotatePlane)
                pt = rs.SurfaceAreaCentroid (pl)[0]
                rs.DeleteObjects (pl)
                #move the capsules a little bit so they won't overlay on each other when I mirror them.
                #rotate the second row of capsules so that they all face the back side.
                if y == 1:
                    rs.MoveObjects (CAPSULE, (0,CoreSizeY-2*CapsuleSizeY+CapsuleSizeY/2,0))
                    rs.RotateObjects (CAPSULE,pt,180,False)
            Floor.append (Row)
            
        #move the middle two capsules forward so that they don't overlay with the core.
        rs.MoveObjects ([Floor[0][1], Floor[0][2]], (0,-CapsuleSizeY/2,0))
        rs.MoveObjects ([Floor[1][1], Floor[1][2]], (0,CapsuleSizeY/2,0))
        if r.random () < Probability:
            rs.MirrorObjects ([Floor[0][0],Floor[0][1]], Cp1, Cp2, False)
        if r.random () < Probability:
            rs.MirrorObjects ([Floor[1][0],Floor[1][1]], Cp3, Cp4, False)
        Building.append (Floor)
    
    #the result of appending lists under "for" loop:
    #      Builing[[[0,1,2,3],[4,5,6,7]],[[8,9,10,11],[12,13,14,15]]]
    #Real: Builing[[[0,1,2,3],[0,1,2,3]],[[0,1, 2, 3],[ 0, 1, 2, 3]]]
    #                  row       row         row           row
    #                      floor                   floor
    #                                building
    #Building[0][0][1]-[building],[floor],[row]-1st floor, 1st row, 2nd object
    #Building[0][0][2]-[building],[floor],[row]-1st floor, 1st row, 3rd object
    
    #use random to radomly mirror some of the capsules.
    #use the diagonal points of the core to mirror the designated capsules.

    return Allcapsules

#use the function to create two sets of buildings.
B1 = makebuilding (0, Core1,nrCapsulesH)
B2 = makebuilding (mygap, Core2,nrCapsulesH2)

#mirror the second set of building so that they don't overlay.
mid3 = midpoint (Cp5,Cp7)
mid4 = midpoint (Cp6,Cp8)
Bldg2 = rs.MirrorObjects (B2, mid3, mid4, False)

rs.DeleteObjects (Crv)

Class Practice Six – Files

 

 

This is the sixth in-class practice saving created objects into files and then importing the file back using file functions in Rhinoceros.

Here is the Python Code for creating random points:


import rhinoscriptsyntax as rs
import random


rs.DeleteObjects (rs.AllObjects ())


nrPoints = rs.GetInteger ("Number of points")
cubeSize = 10


rs.EnableRedraw (False)


for i in range (0, nrPoints):
    x = random.uniform (0, cubeSize)
    y = random.uniform (0, cubeSize)
    z = random.uniform (0, cubeSize)
    point = rs.AddPoint (x, y, z)
    
    #we can assign specific colors to rgb by giving the exact number. e.g.(for red, r=255,g=0,b=0)
    r = random.randint (0, 255)
    g = random.randint (0, 255)
    b = random.randint (0, 255)
    rs.ObjectColor (point, (r, g, b))


rs.EnableRedraw (True)

Here is the Python Code for saving the created points into a file:


import rhinoscriptsyntax as rs

points = rs.GetObjects ("Please select points")

#get gilename and location from user
#saved this to file named "savedfile", and the file has a list of coordinates
filename = rs.SaveFileName ()

#opening the file for access
myfile = open(filename,"w")

for point in points:
    coord = rs.PointCoordinates (point)
    x = coord[0]
    y = coord[1]
    z = coord[2]
    
    
    #r = rs.ObjectColor (point)[0]
    #g = rs.ObjectColor (point)[1]
    #b = rs.ObjectColor (point)[2]
    
    #print (str(x) + "," + str(y) + "," + str(z))
    
    #below means what is x/y/z is replaced by %.2f/%.2f/%.2f, .2 makes the printed coordinates only show 2 digits
    #print ("coord X: %.2f, coord Y: %.2f, coord Z: %.2f" %(x,y,z))
    
    
    color = rs.ObjectColor (point)
    print color
    r = color.R
    g = color.G
    b = color.B
    
    #print (str(x) + "," + str(y) + "," + str(z))
    

    newLine = ("%.2f,%.2f,%.2f,%d,%d,%d\n" %(x,y,z,r,g,b))
    myfile.write(newLine)
    
    
myfile.close()

Here is the Python Code for importing the saved file back:


import rhinoscriptsyntax as rs

rs.DeleteObjects (rs.AllObjects ())

filename = rs.OpenFileName ()

#open the saved file
file = open (filename, "r")

text = file.readlines ()

file.close()

#above process was running at background, so we print it to see if it is working
#for line in text:
    #normalLine = line.strip()
    #print normalLine
    

#it will read the file and bring the values(x,y,z)(r,g,b) in
for line in text:
    normalLine = line.strip()
    values = line.split(",")
    
    x = values[0]
    y = values[1]
    z = values[2]
    
    #we need to cast the rgb into integer
    r = int(values[3])
    g = int(values[4])
    b = int(values[5])
    
    coord = (x,y,z)
    color = (r,g,b)
    
    point = rs.AddPoint (coord)
    rs.ObjectColor (point, color)
    
    #coord = (values[0], values[1], values[2])
    #coord = (values[0], values[1], values[2])
    
    #print coord

Class Practice Five – Parametric Surface

 

This is the fifth in-class practice doing a parametric surface using operations on 3D elements in Rhinoceros.

Here is the Python Code:


import rhinoscriptsyntax as rs
import math as m

surfX = 5.0
surfY = 5.0
surfHeight = .25

rs.DeleteObjects (rs.AllObjects ())
rs.EnableRedraw (False)

nrPtsX = 20
stepX = surfX / nrPtsX

nrPtsY = 20
stepY = surfY / nrPtsY

curves = []

for j in rs.frange (0,surfY,stepY):
    points = []
    for i in rs.frange (0,surfX,stepX):
        #z = m.sin (i*m.pi*2)*surfHeight*j
        z = m.sin (i*m.pi*2)*m.sin (j*m.pi*2)*.1
        #z = m.sin (i*m.pi*2)*m.sin (j*m.pi*2)*surfHeight
        points.append(rs.AddPoint ([i,j,z]))
        
    #rs.AddCurve (points)
    curves.append(rs.AddCurve (points))
    rs.DeleteObjects (points)

rs.AddLoftSrf (curves)
rs.DeleteObjects (curves)

rs.EnableRedraw (True)

surface = rs.GetObject ("Please select surface")

#U=horizontal=0 / V=vertical=1
domainU = rs.SurfaceDomain (surface, 0)
domainV = rs.SurfaceDomain (surface, 1)
print domainU

nrSpheresU = 5
nrSpheresV = 7

spheres = []

for j in rs.frange (0.5/nrSpheresV,1,1/nrSpheresV):
    for i in rs.frange (0.5/nrSpheresU,1,1/nrSpheresU):
        uParam = domainU[1]*i
        vParam = domainV[1]*j
        point = rs.EvaluateSurface (surface, uParam, vParam)
        spheres.append (rs.AddSphere (point, .1))
        
        
thickness = 0.05
extrusionCurve = rs.AddLine ([0,0,0],[0,0,thickness])
wall = rs.ExtrudeSurface (surface, extrusionCurve)
rs.BooleanDifference (wall, spheres)

Exercise Four – Hierarchy, Composition and Transformation

 

 

 

 

 

This is Exercise Four: Hierarchy, Composition and Transformation. For this exercise, we were asked to create a record of the objects created by our program in the form of a data structure.

Here is the Python Code:


import rhinoscriptsyntax as rs
import random as r

lotSizeX = 60
lotSizeY = 100

roomSizeX = 6
roomSizeY = 10
roomSizeH = 3.5

offsetDist = 0.25
thickness = 0.1
Crv = []

def makeBlock (room, blockHeight):
    #find curves where the block will be created.
    origin = rs.CurveStartPoint (room)
    midPoint = [origin[0] + roomSizeX / 2, origin[1] + roomSizeY / 2, 0]
    plan = rs.OffsetCurve (room, midPoint, offsetDist)
    #extrude the exterior facades
    roof = [origin[0] + roomSizeX / 2, origin[1] + roomSizeY / 2, blockHeight]
    Crv.append (plan)
    facade = rs.ExtrudeCurveStraight (plan, midPoint, roof)
    #find and extrude the inner facades
    innerPlan = rs.OffsetCurve (plan, midPoint, thickness)
    innerFacade = rs.ExtrudeCurveStraight (innerPlan, midPoint, roof)
    #create surface between exterior and inner facades, and copy it to the top
    bottomFacade = rs.AddLoftSrf ([plan, innerPlan])
    topFacade = rs.CopyObject (bottomFacade, (0,0,blockHeight))
    #explode the exterior facades and find the one that will have a window
    facade2 = rs.ExplodePolysurfaces (facade, False)
    wall = facade2[1]
    #join the facades together to create solid wall
    thickWall = rs.JoinSurfaces ([facade, innerFacade, bottomFacade, topFacade], True)
    #find the center point of the surface, and create a sphere on it.
    point = rs.SurfaceAreaCentroid (wall)[0]
    sphere = rs.AddSphere (point, 0.5)
    #booleandifference between the wall and the sphere to create the window hole.
    openWall = rs.BooleanDifference (thickWall, sphere)
    rs.DeleteObjects (facade2)
    #create floor slab and copy it to the ceiling
    floor = rs.ExtrudeCurveStraight (plan, [0,0,0], [0,0,thickness])
    floorSlab = rs.CapPlanarHoles (floor)

    ceiling = rs.CopyObject (floor, (0, 0, blockHeight - thickness))
    #booleanunion all the solid walls together to create the block wanted.
    block = rs.BooleanUnion ([openWall, floor, ceiling])
    
    rs.DeleteObjects (plan)
    rs.DeleteObjects (innerPlan)

    return block

rs.DeleteObjects (rs.AllObjects ())

#we need to define the workplane before create a rectangle.
plane = rs.WorldXYPlane ()
C = rs.AddRectangle (plane, lotSizeX, lotSizeY)

nrRoomsX = lotSizeX // roomSizeX
nrRoomsY = lotSizeY // roomSizeY

#use three "for" loop to create blocks in three directions.
for y in range (0, nrRoomsX):

    for x in range (0, nrRoomsX):
        
        for z in range (0, nrRoomsX):
            #print (str(x) + "," + str(y) + "," + str(z))
            #we also need to move the workplane so that to crate a new rectangle at the new place.
            newPlane = rs.MovePlane (plane, [x*(roomSizeX+roomSizeY),y*roomSizeY,z*roomSizeH])
            newRoom = rs.AddRectangle (newPlane, roomSizeX, roomSizeY)
            Crv.append (newRoom)
            #make the block with the defined makeBlock function.
            block = makeBlock (newRoom, 3)
            
            #find the center point which will be used to rotate the blocks
            pl = rs.AddPlanarSrf (newRoom)
            pt = rs.SurfaceAreaCentroid (pl)[0]
            rs.DeleteObjects (pl)
            
            #use "if" to define which blocks are going to be rotated
            #use variable to create connection between functions!!
            if x == 0:
                rotation = -90
            if x == 1:
                rotation = 0
            if x == nrRoomsX-1:
                rotation = 90
            if r.random () < .25:
                rs.RotateObjects (block, pt, rotation, False)

            #use random to randomly delete 25% of the blocks.
            if r.random () < .25:
                rs.DeleteObject (block)

#delete the previouslly created curves.
rs.DeleteObjects (Crv)
rs.DeleteObjects (C)

Class Practice Four – Data Structure

 

 

This is the fourth in-class practice making streets in the city, and adding details to the buildings using the data structure in Rhinoceros.

Here is the Python Code:


import rhinoscriptsyntax as rs
import random
citySizeX = 200
citySizeY = 300
lotSizeX = 40
lotSizeY = 50
offsetDist = 7.5
masterHeight = 30
def makeBuilding (lot, buildingHeight):
    origin = rs.CurveStartPoint (lot)
    #calculate midpoint for direction of offset - inside of lot
    midPoint = [origin[0] + lotSizeX / 2, origin[1] + lotSizeY / 2, 0]
    #rs.AddPoint (midPoint)
    plan = rs.OffsetCurve (lot, midPoint, offsetDist)
    roof = [origin[0] + lotSizeX / 2, origin[1] + lotSizeY / 2, buildingHeight]
    building = rs.ExtrudeCurveStraight (plan, midPoint, roof)
    rs.CapPlanarHoles (building)
    return building
    
def detailBuilding (building):
    f = 0.8   #shrinking factor
    bb = rs.BoundingBox (building)
    origin = bb[0]
    height = rs.Distance (bb[0], bb[4])
    part1 = rs.ScaleObject (building, origin,[1,1,1/3])
    part2 = rs.CopyObject (building, [0,0,height/3])
    bb2 = rs.BoundingBox (part2)
    rs.ScaleObject (part2, bb2[1], [f,f,1])
    part3 = rs.CopyObject (part2, [0,0,height/3])
    bb3 = rs.BoundingBox (part3)
    rs.ScaleObject (part3, bb3[3], [f,f,1])
    
    return [part1, part2, part3]
    
def makeCity ():
    cityBuildings = []
    plane =rs.WorldXYPlane()
    rs.AddRectangle (plane, citySizeX, citySizeY)
    ptPark = rs.GetPoint ("Please select park location: ")
    ptCenter = rs.GetPoint ("Please select center location: ")
    nrLotsX = citySizeX // lotSizeX
    nrLotsY = citySizeY // lotSizeY
    #print (nrLotsX)
    rs.EnableRedraw (False)
    for j in range (0, nrLotsY):
        for i in range (0, nrLotsX):
            #print (str(i) + "," + str(j))
        
            newPlane = rs.MovePlane (plane, [i*lotSizeX, j*lotSizeY, 0])
            newLot = rs.AddRectangle (newPlane, lotSizeX, lotSizeY)
        
            #if lot is close enough to ptPark, don't make building
            ptLot = rs.CurveStartPoint (newLot)
            distPark = rs.Distance (ptLot, ptPark)
            if (distPark > 40):
                newHeight = random.uniform (60, 100)
                distCenter = rs.Distance (ptLot, ptCenter)
                suburbanFactor = 2000/(distCenter**.5)
                #centerHeight = newHeight
                newBuilding = makeBuilding(newLot, newHeight + suburbanFactor)
                cityBuildings.append (newBuilding)
    rs.EnableRedraw (True)
    return cityBuildings

rs.DeleteObjects (rs.AllObjects())
cityList = makeCity()
rs.MessageBox ("Press OK to continue...")
rs.HideObjects (cityList)
avenue = rs.GetPoints(True)
rs.ShowObjects (cityList)
avenuePoly = rs.AddPolyline (avenue)
avenueOffset = rs.OffsetCurve (avenuePoly, [1,0,0], lotSizeX*.5)
avenueBuildings =[]
for building in cityList:
    intersection1 = rs.CurveBrepIntersect (avenuePoly, building)
    intersection2 = rs.CurveBrepIntersect (avenueOffset, building)
    if intersection1 or intersection2:
        avenueBuildings.append (building)
#remove avenueBuildings from cityList
for building in avenueBuildings:
    cityList.remove (building)

rs.DeleteObjects (avenueBuildings)

#click and change a building, while loop makes the click function happen as many times as you want, as long as you click
#when right click, you are kicked out of the while loop
specialBuilding = rs.GetObject ("Please select the building to change")

while specialBuilding:
    
    if specialBuilding in cityList:
    
        detailedBuilding = detailBuilding (specialBuilding)
        cityList.remove (specialBuilding)
        cityList.extend ([detailedBuilding[2]])
        print cityList
    else:
        print "Cannot change that object!"
    specialBuilding = rs.GetObject ("Please select the building to change")

Exercise Three – Solids and Surfaces

This is Exercise Three: Solids and Surfaces. For this exercise, we were asked to create one or more Python functions that manage one or more three‐dimensional elements that must be created from geometric operations with invocation of commands to create solids or surfaces.

Here is the Python Code:

 


import rhinoscriptsyntax as rs
import random as r

lotSizeX = 60
lotSizeY = 100

roomSizeX = 6
roomSizeY = 10
roomSizeH = 3.5

offsetDist = 0.25

Crv = []

def makeBlock (room, blockHeight):
    #create a list to save the surfaces.
    blocksrf = []
    #create blocks and explode them into six surfaces.
    origin = rs.CurveStartPoint (room)
    midPoint = [origin[0] + roomSizeX / 2, origin[1] + roomSizeY / 2, 0]
    plan = rs.OffsetCurve (room, midPoint, offsetDist)
    roof = [origin[0] + roomSizeX / 2, origin[1] + roomSizeY / 2, blockHeight]
    Crv.append (plan)
    facade = rs.ExtrudeCurveStraight (plan, midPoint, roof)
    rs.CapPlanarHoles (facade)
    facade2 = rs.ExplodePolysurfaces (facade, True)
    blocksrf = facade2
    #select and save one surface into a list.
    wall = facade2[3]
    #find the center point of the surface, and create a sphere on it.
    point = rs.SurfaceAreaCentroid (wall)[0]
    rs.AddPoint (point)
    sphere = rs.AddSphere (point, 0.5)
    #extrude the surface so that to make booleandifference between it and the sphere.
    thickness = 0.1
    extrusionCurve = rs.AddLine ([0,0,0],[0,thickness,0])
    wall = rs.ExtrudeSurface (wall, extrusionCurve)
    rs.BooleanDifference (wall, sphere)
    #join the six surfaces back to a block and give it an ID, and return it.
    joinedblock = rs.JoinSurfaces (blocksrf)
    return joinedblock

rs.DeleteObjects (rs.AllObjects ())

#we need to define the workplane before create a rectangle.
plane = rs.WorldXYPlane ()
C = rs.AddRectangle (plane, lotSizeX, lotSizeY)

nrRoomsX = lotSizeX // roomSizeX
nrRoomsY = lotSizeY // roomSizeY

#use three for loop to create blocks in three directions.
for j in range (0, nrRoomsY):

    for i in range (0, nrRoomsX):
        
        for h in range (0, nrRoomsX):
            print (str(i) + "," + str(j) + "," + str(h))
            #we also need to move the workplane so that to crate a new rectangle at the new place.
            newPlane = rs.MovePlane (plane, [i*roomSizeX,j*roomSizeY,h*roomSizeH])
            newRoom = rs.AddRectangle (newPlane, roomSizeX, roomSizeY)
            Crv.append (newRoom)
            #make the block with the defined makeBlock function.
            block = makeBlock (newRoom, 3)
            #use random to randomly delete 25% of the blocks.
            if r.random () < .25:
                rs.DeleteObject (block)
#delete the previouslly created rectangles.
rs.DeleteObjects (Crv)
rs.DeleteObjects (C)

Class Practice Three – City Mass

 

 

 

This is the third in-class practice making an urban model using control structure in Rhinoceros. In this urban model, we also created empty space for central park, and we selected a spot where the buildings are much taller as the downtown area.

Here is the Python Code:


import rhinoscriptsyntax as rs
import random

citySizeX = 1000
citySizeY = 2000

lotSizeX = 40
lotSizeY = 50

offsetDist = 7.5

masterHeight = 30

def makeBuilding (lot, buildingHeight):
    origin = rs.CurveStartPoint (lot)
    #rs.AddPoint (origin)
    #this command will show the origin point on each rectangle
    #pt=[1,2,3]([x,y,z]) - (0,1,2), so: py[0]=1/pt[1]=2/pt[2]=3
    midPoint = [origin[0] + lotSizeX / 2, origin[1] + lotSizeY / 2, 0]
    rs.AddPoint (midPoint)
    plan = rs.OffsetCurve (lot, midPoint, offsetDist)
    roof = [origin[0] + lotSizeX / 2, origin[1] + lotSizeY / 2, buildingHeight]
    facade = rs.ExtrudeCurveStraight (plan, midPoint, roof)
    rs.CapPlanarHoles (facade)

rs.DeleteObjects (rs.AllObjects ())

#addRectangle needs to define plane in its parameter
plane = rs.WorldXYPlane ()
rs.AddRectangle (plane, citySizeX, citySizeY)


#// division, when it is only one /, the results could be non-integer, and it produce an error "float"
nrLotsX = citySizeX // lotSizeX
nrLotsY = citySizeY // lotSizeX
print (nrLotsX)

#make rooms for parks in our city:
ptPark = rs.GetPoint ("Please select park location:")
ptCenter = rs.GetPoint ("Please select center location:")

#in range, the results are always one less than the last range
#for example, (0,7), the results are 0,1,2,3,4,5,6
#range inside another range:
for j in range (0, nrLotsY):

    for i in range (0, nrLotsX):
        print (str(i) + "," + str(j))
        #the command above will print a list of i and j pairs
        #the command below will produce a roll of #i lots and a column of #j lots
        
        newPlane = rs.MovePlane (plane, [i*lotSizeX,j*lotSizeY,0])
        #with the command below, a lot of rectangles will be produced at the same place, so we need to move them with the command above
        newLot = rs.AddRectangle (newPlane, lotSizeX, lotSizeY)
        
        #if lot is close enough to ptPark, don't make building
        ptLot = rs.CurveStartPoint (newLot)
        distPark = rs.Distance (ptLot, ptPark)
        #when the distance between ptLot and ptPark is bigger than our setting, it will make building:
        if (distPark > 200):
            newHeight = random.uniform (60,200)
            distCenter = rs.Distance (ptLot, ptCenter)
            #suburbanFactor = distCenter * .2
            suburbanFactor = 2000/(distCenter**.5)
            centerHeight = newHeight
            makeBuilding(newLot, newHeight + suburbanFactor)

Exercise Two – Functions and Variables

 

 

 

 

 

 

 

 

This is Exercise Two: Functions and variables. For this exercise, we were asked to program a parametric description or convert our previous exercise into a parametric program by using variables and functions.

 

Here is the Python Code:


import rhinoscriptsyntax as rs
import random as r

lotSizeX = 60
lotSizeY = 100

roomSizeX = 6
roomSizeY = 10
roomSizeH = 3.5

offsetDist = 0.25

Crv = []

def makeBuilding (room, buildingHeight):
    origin = rs.CurveStartPoint (room)
    midPoint = [origin[0] + roomSizeX / 2, origin[1] + roomSizeY / 2, 0]
    plan = rs.OffsetCurve (room, midPoint, offsetDist)
    roof = [origin[0] + roomSizeX / 2, origin[1] + roomSizeY / 2, buildingHeight]
    Crv.append (plan)
    facade = rs.ExtrudeCurveStraight (plan, midPoint, roof)
    rs.CapPlanarHoles (facade)
    return facade

rs.DeleteObjects (rs.AllObjects ())

plane = rs.WorldXYPlane ()
C = rs.AddRectangle (plane, lotSizeX, lotSizeY)

nrRoomsX = lotSizeX // roomSizeX
nrRoomsY = lotSizeY // roomSizeY
print (nrRoomsX)

for j in range (0, nrRoomsY):

    for i in range (0, nrRoomsX):
        
        for h in range (0, nrRoomsX):
            print (str(i) + "," + str(j) + "," + str(h))
            newPlane = rs.MovePlane (plane, [i*roomSizeX,j*roomSizeY,h*roomSizeH])
            newRoom = rs.AddRectangle (newPlane, roomSizeX, roomSizeY)
            Crv.append (newRoom)
            building = makeBuilding (newRoom, 3)
        
            if r.random () < .25:
                rs.DeleteObject (building)
                
rs.DeleteObjects (Crv)
rs.DeleteObjects (C)