start balcony
This commit is contained in:
@@ -52,5 +52,5 @@ class Facade:
|
|||||||
return self.rdata["inter_floor"] >= rd.random()
|
return self.rdata["inter_floor"] >= rd.random()
|
||||||
|
|
||||||
def get_dimentions(self) -> tuple[int]:
|
def get_dimentions(self) -> tuple[int]:
|
||||||
return ( self.vertices[0].get_height(), self.vertices[0].get_len())
|
return ( self.vertices[0].get_height(), len(self.vertices[0]))
|
||||||
|
|
||||||
@@ -1,17 +1,49 @@
|
|||||||
import random as rd
|
import random as rd
|
||||||
|
from buildings.geometry.Point import Point
|
||||||
|
from buildings.geometry.Vertice import Vertice
|
||||||
from buildings.elements.Window import Window
|
from buildings.elements.Window import Window
|
||||||
|
|
||||||
class Balcony:
|
class Balcony:
|
||||||
def __init__(self, rdata, max_width : int, windows : Window):
|
def __init__(self, rdata, windows : Window):
|
||||||
self.rdata = rdata
|
self.rdata = rdata
|
||||||
self.max_width = max_width
|
|
||||||
self.windows = windows
|
self.windows = windows
|
||||||
self.length = self.get_len()
|
self.length = self.get_len()
|
||||||
self.has_multiple = self.has_multiple_balcony()
|
self.has_multiple = self.has_multiple_balcony()
|
||||||
|
self.follow_window = self.follow_window()
|
||||||
|
|
||||||
|
def get_structures(self) -> list[Vertice]:
|
||||||
|
attach_points = self.get_attach_points()
|
||||||
|
len_attach_points = len(attach_points)
|
||||||
|
min_wid = self.rdata["balcony"]["size"]["min_width"]
|
||||||
|
growth_chance = self.rdata["balcony"]["growth"]
|
||||||
|
midpoint = len_attach_points//2
|
||||||
|
x1,x2 = midpoint, len_attach_points - midpoint
|
||||||
|
|
||||||
|
structures = []
|
||||||
|
while True:
|
||||||
|
x1 -= 1
|
||||||
|
x2 += 1
|
||||||
|
if x1 < 0 : break
|
||||||
|
if attach_points[x2] - attach_points[x1] + 1 < min_wid: continue
|
||||||
|
if growth_chance < rd.random():
|
||||||
|
structures.append(self.create_structure(attach_points[x1], attach_points[x2]))
|
||||||
|
if not self.has_multiple: break
|
||||||
|
|
||||||
|
|
||||||
|
def get_attach_points(self) -> list[int]:
|
||||||
|
points = [i for i in range(self.max_width)]
|
||||||
|
if self.follow_window:
|
||||||
|
for w in self.windows.windows:
|
||||||
|
for i in range(w.x1, w.x2+1):
|
||||||
|
points.remove(i)
|
||||||
|
|
||||||
|
return points
|
||||||
|
|
||||||
|
def create_structure(self, x1 : int, x2 : int) -> Vertice:
|
||||||
|
return Vertice(Point(x1,0,0), Point(x2,0,self.length-1))
|
||||||
|
|
||||||
def follow_window(self) -> bool:
|
def follow_window(self) -> bool:
|
||||||
pass
|
return self.windows.ypadding > 3
|
||||||
|
|
||||||
|
|
||||||
def has_multiple_balcony(self) -> bool:
|
def has_multiple_balcony(self) -> bool:
|
||||||
if self.max_width < self.rdata["balcony"]["multiple"]["min_width"]: return False
|
if self.max_width < self.rdata["balcony"]["multiple"]["min_width"]: return False
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ class Glass:
|
|||||||
|
|
||||||
def reset_groups(self):
|
def reset_groups(self):
|
||||||
self.group1, self.group2 = [], []
|
self.group1, self.group2 = [], []
|
||||||
|
|
||||||
def get_len(self):
|
def __len__(self):
|
||||||
return self.x2 - self.x1 + 1
|
return self.x2 - self.x1 + 1
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ class Window:
|
|||||||
self.materials = materials
|
self.materials = materials
|
||||||
with editor.pushTransform(Transform((self.padding,self.ypadding,0))):
|
with editor.pushTransform(Transform((self.padding,self.ypadding,0))):
|
||||||
for g in self.windows:
|
for g in self.windows:
|
||||||
len = g.get_len()
|
leng = len(g)
|
||||||
g.build(editor, materials[1], materials[2])
|
g.build(editor, materials[1], materials[2])
|
||||||
self.build_crossbars(g.x1, g.x2, len)
|
self.build_crossbars(g.x1, g.x2, leng)
|
||||||
if len > 1: self.build_border_radius(g.x1, g.x2)
|
if leng > 1: self.build_border_radius(g.x1, g.x2)
|
||||||
|
|
||||||
def build_crossbars(self, x1 : int, x2 : int, len : int):
|
def build_crossbars(self, x1 : int, x2 : int, len : int):
|
||||||
if self.has_vertical_crossbar and self.height >= self.rdata["crossbars"]["min_height_for_vertical_crossbar"]:
|
if self.has_vertical_crossbar and self.height >= self.rdata["crossbars"]["min_height_for_vertical_crossbar"]:
|
||||||
@@ -67,11 +67,12 @@ class Window:
|
|||||||
is_even= slices % 2 == 0
|
is_even= slices % 2 == 0
|
||||||
is_window, gap = True, 0
|
is_window, gap = True, 0
|
||||||
remainder = self.width - (window_size*windows_count + inter_size*inter_count)
|
remainder = self.width - (window_size*windows_count + inter_size*inter_count)
|
||||||
|
|
||||||
if windows_count % 2 == 1 and inter_count % 2 == 1:
|
if windows_count % 2 == 1 and inter_count % 2 == 1:
|
||||||
inter_count -= 1
|
inter_count -= 1
|
||||||
remainder += inter_size
|
remainder += inter_size
|
||||||
is_even = not is_even
|
is_even = not is_even
|
||||||
print(window_size,windows_count,inter_size,inter_count,remainder,self.width,"\n\n")
|
|
||||||
for i in range(1,slices+1):
|
for i in range(1,slices+1):
|
||||||
wsize,isize = window_size, inter_size
|
wsize,isize = window_size, inter_size
|
||||||
if is_even and i == mid: wsize, isize = wsize*2, isize*2
|
if is_even and i == mid: wsize, isize = wsize*2, isize*2
|
||||||
@@ -90,10 +91,10 @@ class Window:
|
|||||||
def alternate(self, windows : list[Glass]):
|
def alternate(self, windows : list[Glass]):
|
||||||
for g in windows:
|
for g in windows:
|
||||||
g.reset_groups()
|
g.reset_groups()
|
||||||
len = g.get_len()
|
leng = len(g)
|
||||||
mid = g.x1 + len//2
|
mid = g.x1 + leng//2
|
||||||
|
|
||||||
is_block, is_even = False, len % 2 == 0
|
is_block, is_even = False, leng % 2 == 0
|
||||||
for x in range(g.x1,g.x2+1):
|
for x in range(g.x1,g.x2+1):
|
||||||
if is_even and x == mid: is_block = not is_block # to keep symetry
|
if is_even and x == mid: is_block = not is_block # to keep symetry
|
||||||
if is_block: g.group2.append(self.create_window(x))
|
if is_block: g.group2.append(self.create_window(x))
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class Vertice(Rectangle):
|
|||||||
case DIRECTION.EAST | DIRECTION.WEST:
|
case DIRECTION.EAST | DIRECTION.WEST:
|
||||||
return [Point(x = self.point1.x, z = self.point1.z - 1),
|
return [Point(x = self.point1.x, z = self.point1.z - 1),
|
||||||
Point(x = self.point2.x, z = self.point2.z + 1)]
|
Point(x = self.point2.x, z = self.point2.z + 1)]
|
||||||
|
|
||||||
def get_len(self):
|
def __len__(self):
|
||||||
return self.point2.x - self.point1.x + self.point2.z - self.point1.z + 1
|
return self.point2.x - self.point1.x + self.point2.z - self.point1.z + 1
|
||||||
|
|
||||||
@@ -42,10 +42,13 @@ buildings:
|
|||||||
inter_floor: 0.5
|
inter_floor: 0.5
|
||||||
balcony:
|
balcony:
|
||||||
proba : 0.25
|
proba : 0.25
|
||||||
|
growth: 0.8 # [growth]% chance to have min_width + 1 balcony length, [growth**2]% chance to have min_width + 2 balcony length, etc
|
||||||
size:
|
size:
|
||||||
min_len : 1
|
min_len : 1
|
||||||
max_len : 3
|
max_len : 3
|
||||||
min_width : 3
|
min_width : 3
|
||||||
multiple:
|
multiple:
|
||||||
|
# probability to have multiple balcony IF POSSIBLE
|
||||||
|
proba: 0.5
|
||||||
min_width: 5
|
min_width: 5
|
||||||
proba: 0.5
|
min_gap: 0
|
||||||
Reference in New Issue
Block a user