 |
CLIP Score: 22.97
from AIDL import *
def city_skyline(building_count: int = 10, max_height: float = 20*inches, max_width: float = 5*inches, min_width: float = 2*inches):
"""
Generates a simple city skyline with a specified number of buildings with varying heights and widths.
"""
import random
# Initialize the main skyline structure
skyline = Solid()
# Track the current x position for placing the next building
current_x = 0
# Loop to create each building
for i in range(building_count):
# Generate random height and width for the building
height = random.uniform(max_height / 2, max_height)
width = random.uniform(min_width, max_width)
# Create a Solid structure for the building
building = Solid(shift=(current_x, 0))
building.body = Rectangle((width / 2, height / 2), width, height)
# Add building to the skyline as an attribute
setattr(skyline, f'building_{i}', building)
# Optionally, add windows as Drawing structures
windows = Drawing()
building.windows = windows
# Add windows as small rectangles on the building
window_width = width / 5
window_height = height / 10
num_windows_vertical = int(height / (2 * window_height))
num_windows_horizontal = int(width / (2 * window_width))
windows.content = []
for row in range(1, num_windows_vertical):
for col in range(1, num_windows_horizontal):
window = Rectangle(((col * 2 * window_width) - (width / 2) + (window_width / 2),
(row * 2 * window_height) - (height / 2) + (window_height / 2)),
window_width * 0.8, window_height * 0.8)
windows.content.append(window)
building.windows = windows
# Update the current x position for the next building
current_x += width + (0.2 * inches) # Add some space between buildings
return skyline
with AIDL_2D:
model = city_skyline()
print(model.Solve())
model.Render()
|
Please write an AIDL program to generate a city skyline
Alright, let's create an AIDL program to generate a city skyline. We'll model a simple skyline with a variety of rectangular buildings. To add some variation, we'll include buildings of different heights and widths, and we can also add windows as engraving details. Here's how we'll proceed:
1. Define the main structure of the skyline.
2. Add individual buildings as Solid structures, with random heights and widths.
3. Optionally, add windows as Drawing structures for engraving details.
Let's start by writing the function definition and importing the necessary modules:
```python
from AIDL import *
def city_skyline(building_count: int = 10, max_height: float = 20*inches, max_width: float = 5*inches, min_width: float = 2*inches):
"""
Generates a simple city skyline with a specified number of buildings with varying heights and widths.
"""
import random
# Initialize the main skyline structure
skyline = Solid()
# Track the current x position for placing the next building
current_x = 0
# Loop to create each building
for i in range(building_count):
# Generate random height and width for the building
height = random.uniform(max_height / 2, max_height)
width = random.uniform(min_width, max_width)
# Create a Solid structure for the building
building = Solid(shift=(current_x, 0))
building.body = Rectangle((width / 2, height / 2), width, height)
# Add building to the skyline
skyline[f'building_{i}'] = building
# Optionally, add windows as Drawing structures
windows = Drawing()
building.windows = windows
# Add windows as small rectangles on the building
window_width = width / 5
window_height = height / 10
num_windows_vertical = int(height / (2 * window_height))
num_windows_horizontal = int(width / (2 * window_width))
windows.content = []
for row in range(1, num_windows_vertical):
for col in range(1, num_windows_horizontal):
windows.content.append(Rectangle(((col * 2 * window_width) - (width / 2) + (window_width / 2),
(row * 2 * window_height) - (height / 2) + (window_height / 2)),
window_width * 0.8, window_height * 0.8))
# Update the current x position for the next building
current_x += width + (0.2 * inches) # Add some space between buildings
return skyline
with AIDL_2D:
model = city_skyline()
print(model.Solve())
model.Render()
```
This program will generate a skyline with a specified number of buildings, each with randomly varying heights and widths within the defined range. Additionally, each building will have windows engraved onto them.
Feel free to adjust the parameters, such as the number of buildings, the minimum and maximum heights, and widths, or even the window configurations. Let me know if you have any further customization or adjustments in mind!
Traceback (most recent call last):
File "/net/projects/ranalab/jz/aidl/AIDL/generation/backend.py", line 21, in dumbrun
exec(code, env)
File "", line 53, in
File "", line 28, in city_skyline
TypeError: 'Solid' object does not support item assignment
The error indicates that the `Solid` object does not support item assignment using square brackets like a dictionary. Instead, we need to assign the substructures as attributes using dot notation. Let's fix that and rerun the program.
Here's the corrected version of the AIDL program to generate a city skyline:
```python
from AIDL import *
def city_skyline(building_count: int = 10, max_height: float = 20*inches, max_width: float = 5*inches, min_width: float = 2*inches):
"""
Generates a simple city skyline with a specified number of buildings with varying heights and widths.
"""
import random
# Initialize the main skyline structure
skyline = Solid()
# Track the current x position for placing the next building
current_x = 0
# Loop to create each building
for i in range(building_count):
# Generate random height and width for the building
height = random.uniform(max_height / 2, max_height)
width = random.uniform(min_width, max_width)
# Create a Solid structure for the building
building = Solid(shift=(current_x, 0))
building.body = Rectangle((width / 2, height / 2), width, height)
# Add building to the skyline as an attribute
setattr(skyline, f'building_{i}', building)
# Optionally, add windows as Drawing structures
windows = Drawing()
building.windows = windows
# Add windows as small rectangles on the building
window_width = width / 5
window_height = height / 10
num_windows_vertical = int(height / (2 * window_height))
num_windows_horizontal = int(width / (2 * window_width))
windows.content = []
for row in range(1, num_windows_vertical):
for col in range(1, num_windows_horizontal):
window = Rectangle(((col * 2 * window_width) - (width / 2) + (window_width / 2),
(row * 2 * window_height) - (height / 2) + (window_height / 2)),
window_width * 0.8, window_height * 0.8)
windows.content.append(window)
building.windows = windows
# Update the current x position for the next building
current_x += width + (0.2 * inches) # Add some space between buildings
return skyline
with AIDL_2D:
model = city_skyline()
print(model.Solve())
model.Render()
```
This should resolve the issue. The buildings are added as attributes to the `skyline` using `setattr()`, and the windows are also assigned correctly within each building.
Let's run this program to generate and render the city skyline model. Let me know if it works or if you need any further modifications!
|