Closed mjcortejo closed 1 year ago
Also need to implement road lanes, draft function:
def render_lanes(canvas, intersection_nodes, edges, lane_width):
for edge, attributes in edges.items():
a, b = edge
a_pos = intersection_nodes[a]
b_pos = intersection_nodes[b]
# Get attributes for the edge
num_lanes = attributes.get('num_lanes', 1)
lane_width = attributes.get('lane_width', lane_width)
lane_color = attributes.get('lane_color', 'black')
# Calculate lane offsets
total_width = num_lanes * lane_width
lane_offset = total_width / 2
# Render each lane
for i in range(num_lanes):
# Calculate the start and end positions of the lane
start_x, start_y = a_pos[0] + i * lane_width - lane_offset, a_pos[1]
end_x, end_y = b_pos[0] + i * lane_width - lane_offset, b_pos[1]
# Render the lane
canvas.create_line(start_x, start_y, end_x, end_y, width=lane_width, fill=lane_color)
Edges currently look like this
edges = [ (1, 2), (1, 4), (2, 3), (2, 5), (3, 6), (4, 5), (4, 7), (5, 6), (5, 8), (6, 9), (7, 8), (8, 9) ]
I want to implement attributes to the edges to that is will look like this:
edges = { (1, 2): { 'has_accident': True, 'road_speed': 20, 'one_way': False }, (2, 3): { 'has_accident': False, 'road_speed': 30, 'one_way': True },
Add more edges and their attributes as needed
}