# CGA : Recursive Highrise Building rule (with good control over floor volumes)

Question asked by MBuehler-esristaff on Dec 5, 2012
Here's a cool simple approach to create some variating building volumes, which can grow thinner from floor to floor.

```/**
* File:    recursiveStepbacks.cga
* Created: 5 Dec 2012 15:27:58 GMT
* Author:  matt6767
*/

version "2012.1"

############################################################
# GENERIC ATTRIBUTES
############################################################

@Group ("Building Volume",0)   @Order(0)
attr Number_Of_Floors  = 8
@Group ("Building Volume")    @Order(1)
attr Groundfloor_Height  = 6
@Group ("Building Volume")    @Order(2)
attr Upperfloor_Height  = 3.5

@Group ("Recursive Detailing",1) @Order(0)
attr Minimal_Stepback_Dimension  = 12
@Group ("Recursive Detailing") @Order(1)
attr Stepback_Probability   = 0.25
@Group ("Recursive Detailing") @Order(2)
attr Stepback_Dim     = rand(5,12)

############################################################
# FUNCTIONS
############################################################

Floorheight_Function(floorNumber) =
case floorNumber == 0 :
Groundfloor_Height
else :
Upperfloor_Height

############################################################
# GENERIC ATTRIBUTES
############################################################
@Hidden
attr Current_Floor = 0

############################################################
# START
############################################################

Lot -->
alignScopeToAxes(y)
LotAligned(scope.sy)

LotAligned(yDim) -->
# create a flat base
extrude(world.y, 100)
split(y) {yDim : BaseVolume | ~1 : NIL}

BaseVolume -->
comp(f) {bottom : NIL | side : BaseFacade | top : alignScopeToGeometry(yUp, 0, longest) BuildingRecursion}

BuildingRecursion -->
case Current_Floor > Number_Of_Floors :
NIL
else :
extrude(world.y, Floorheight_Function(Current_Floor))
FloorVolume
set (Current_Floor, Current_Floor + 1)
comp(f) {top : FloorShape | all : NIL}

FloorShape -->
case p(Stepback_Probability) && scope.sx > Minimal_Stepback_Dimension :
alignScopeToGeometry(yUp, 0, longest)
split(x) {Stepback_Dim : BalconyShape | ~1 : BuildingRecursion}
else :
alignScopeToGeometry(yUp, 0, longest)
BuildingRecursion

############################################################
############################################################

FloorVolume -->
case Current_Floor == Number_Of_Floors :
# top floor
color(1,0,0)
else :
Floor.

color(.3,.3,.3)
X.

BalconyShape -->
case Current_Floor > Number_Of_Floors :
NIL
else :
extrude(1)
comp(f) {top : NIL | bottom : NIL | front : BalconyWall | back : BalconyWall | left : BalconyWall }

BalconyWall -->
color(.5,.7,.5)
set (material.opacity, 0.7)
```

[ATTACH=CONFIG]19717[/ATTACH]