Redo Lane

This commit is contained in:
2024-06-06 19:53:00 +02:00
parent 45c7560352
commit 9867909e9f
3 changed files with 65 additions and 36 deletions

View File

@@ -5,40 +5,31 @@ import random
class Line:
def __init__(self, coordinates, line_materials):
self.coordinates = coordinates
self.line_materials = line_materials
self.surface = []
def get_surface(self):
resolution, distance = curve_tools.resolution_distance(
self.coordinates, 6)
curve_points = curve_tools.curve(self.coordinates, resolution)
# Compute the line
self.coordinates = coordinates # Full lines coordinates, not just endpoints
self.line_materials = line_materials # From lines.json
self.coordinates_with_blocks = [] # Output
def get_blocks(self):
pattern_length = 0
pattern_materials = []
# Create the pattern materials list with correct materials depending on the selected pattern.
for pattern in self.line_materials:
pattern_length += pattern[1]
for _ in range(pattern[1]):
pattern_materials.append(pattern[0])
pattern_iteration = 0
for i in range(len(curve_points)-1):
line = segment_tools.discrete_segment(
curve_points[i], curve_points[i+1])
for coordinate in line:
block = random.choices(
list(pattern_materials[pattern_iteration].keys()),
weights=pattern_materials[pattern_iteration].values(),
k=1)[0]
if block != 'None':
self.surface.append((coordinate, block))
for coordinate in self.coordinates:
block = random.choices(
list(pattern_materials[pattern_iteration].keys()),
weights=pattern_materials[pattern_iteration].values(),
k=1)[0]
if block != 'None':
self.coordinates_with_blocks.append((coordinate, block))
pattern_iteration += 1
if pattern_iteration >= pattern_length:
pattern_iteration = 0
return self.surface
return self.coordinates_with_blocks