building = function(svg, dime) {
const building = svg.append('g')
const h = height-dime.height-dime.y
const x = { left:dime.x-60, middle:dime.x, right:dime.x + 60 }
const y = { topTop:h-30, topMiddle:h, topBottom:h+30, bottomMiddle:h+dime.height, bottomBottom:h+dime.height+30 }
const colours = { top:'#1F33B5', left:'#18299A', right:'#1A2CA7' }
building.append('polygon').attr('points',
x.middle+', '+ y.topTop + ' '+
x.right+', '+ y.topMiddle + ' '+
x.middle+', '+ y.topBottom + ' '+
x.left +', '+ y.topMiddle
).attr('fill', colours.top)
.attr('stroke', '#44DADA')
.attr('stroke-width', 1)
const sides = ['left', 'right']
sides.forEach((side) =>
building.append('polygon').attr('points',
x.middle+','+y.topBottom+' '+
x[side]+','+y.topMiddle+' '+
x[side]+','+y.bottomMiddle+' '+
x.middle+','+y.bottomBottom
).attr('fill', colours[side])
.attr('stroke', '#44DADA')
.attr('stroke-width', 1)
)
const windowSpace = 10;
let windowCount = dime.height/windowSpace;
while(windowCount > 1) {
let top = h + (windowSpace * windowCount)
building.append('polyline')
.attr('points', x.left+','+(top-9)+' '+x.middle+','+(top+21)+' '+x.right+','+(top-9))
.attr('stroke', '#44DADA')
.attr('fill', 'transparent')
.attr('stroke-width', 2)
.attr('opacity', 0.1)
if(Math.random() >= 0.8) {
building.append('polyline')
.attr('points', x.left+','+(top-9)+' '+x.middle+','+(top+21)+' '+x.right+','+(top-9))
.attr('stroke', '#44DADA')
.attr('fill', 'transparent')
.attr('stroke-width', 2)
.attr('opacity', 0.1)
}
if(Math.random() >= 0.9) {
let positions = [
(x.middle+5)+','+(top+24)+' '+ (x.right-20) + ','+ (top+6),
(x.middle-5)+','+(top+24)+' '+ (x.left+20) + ','+ (top+6),
(x.middle-30)+','+(top+1)+' '+ (x.left+5) + ','+ (top-11),
(x.middle+30)+','+(top+1)+' '+ (x.right-5) + ','+ (top-11),
]
let points = positions[Math.floor(Math.random() * positions.length)]
building.append('polyline')
.attr('points', points)
.attr('stroke', '#BAEAEA')
.attr('fill', 'transparent')
.style("stroke-dasharray", ("1, 7"))
.attr('stroke-linecap', 'round')
.attr('stroke-width', 3)
.attr('opacity', 0.5)
}
--windowCount
}
}