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)

Leave a Reply

Your email address will not be published. Required fields are marked *