 |
CLIP Score: 23.81
from AIDL import *
def city_skyline(building_count: int = 10, max_height: float = 8 * inches, min_height: float = 3 * inches, max_width: float = 1.5 * inches, min_width: float = 0.5 * inches):
"""
Model a simple city skyline with a given amount of buildings.
Each building will have random heights and widths within the specified ranges.
"""
# Random module for generating building dimensions
import random
skyline = Assembly()
for i in range(building_count):
building_height = random.uniform(min_height, max_height)
building_width = random.uniform(min_width, max_width)
building = Solid(shift=(i * (max_width + 0.2 * inches), 0)) # Add some spacing between buildings
building.body = Rectangle((0, building_height / 2), building_width, building_height)
setattr(skyline, f'building_{i}', building)
# Add window details as a Drawing
windows = Drawing()
building.windows = windows
rows = int(building_height // (0.4 * inches))
columns = int(building_width // (0.4 * inches))
windows.window_list = []
for r in range(rows):
for c in range(columns):
# Create a small rectangle for each window
window = Rectangle(((-building_width / 2 + 0.2 * inches + c * 0.4 * inches),
(building_height / 2 - 0.2 * inches - r * 0.4 * inches)), 0.3 * inches, 0.3 * inches)
windows.window_list.append(window)
return skyline
with AIDL_2D:
model = city_skyline()
print(model.Solve())
model.Render()
|
Please write an AIDL program to generate a city skyline
Sure! To generate a city skyline, we can create a model consisting of various rectangular buildings with different heights and widths. We can add detailing elements like windows as engraving lines.
Let's begin with a simple skyline with varying building heights and widths and basic details for windows.
```python
from AIDL import *
def city_skyline(building_count: int = 10, max_height: float = 8 * inches, min_height: float = 3 * inches, max_width: float = 1.5 * inches, min_width: float = 0.5 * inches):
"""
Model a simple city skyline with a given amount of buildings.
Each building will have random heights and widths within the specified ranges.
"""
# Random module for generating building dimensions
import random
skyline = Assembly()
for i in range(building_count):
building_height = random.uniform(min_height, max_height)
building_width = random.uniform(min_width, max_width)
building = Solid(shift=(i * (max_width + 0.2 * inches), 0)) # Add some spacing between buildings
building.body = Rectangle((0, building_height / 2), building_width, building_height)
skyline[f'building_{i}'] = building
# Add window details as a Drawing
windows = Drawing()
building.windows = windows
rows = int(building_height // (0.4 * inches))
columns = int(building_width // (0.4 * inches))
for r in range(rows):
for c in range(columns):
# Create a small rectangle for each window
window = Rectangle(((-building_width / 2 + 0.2 * inches + c * 0.4 * inches),
(building_height / 2 - 0.2 * inches - r * 0.4 * inches)), 0.3 * inches, 0.3 * inches)
windows[window.center] = window
return skyline
with AIDL_2D:
model = city_skyline()
print(model.Solve())
model.Render()
```
In this program:
1. We import the required modules.
2. We define the `city_skyline` function that takes parameters for the number of buildings, and their height and width ranges.
3. We create the root `Assembly` structure for the skyline to hold individual buildings.
4. We generate each building with random heights and widths within the specified ranges.
5. We add windows to each building via the `Drawing` structure, with simple rectangles representing the windows.
6. Finally, we use the standard snippet to solve and render the model.
Feel free to adjust the parameters and add more details to each building or the windows as you see fit!
Traceback (most recent call last):
File "/net/projects/ranalab/jz/aidl/AIDL/generation/backend.py", line 21, in dumbrun
exec(code, env)
File "", line 41, in
File "", line 21, in city_skyline
TypeError: 'Assembly' object does not support item assignment
I apologize for that mistake. In AIDL, you can't assign children to an `Assembly` using dictionary-style notation. Instead, you should use attribute-style assignment.
Let's correct the implementation by using Python attribute assignment:
```python
from AIDL import *
def city_skyline(building_count: int = 10, max_height: float = 8 * inches, min_height: float = 3 * inches, max_width: float = 1.5 * inches, min_width: float = 0.5 * inches):
"""
Model a simple city skyline with a given amount of buildings.
Each building will have random heights and widths within the specified ranges.
"""
# Random module for generating building dimensions
import random
skyline = Assembly()
for i in range(building_count):
building_height = random.uniform(min_height, max_height)
building_width = random.uniform(min_width, max_width)
building = Solid(shift=(i * (max_width + 0.2 * inches), 0)) # Add some spacing between buildings
building.body = Rectangle((0, building_height / 2), building_width, building_height)
setattr(skyline, f'building_{i}', building)
# Add window details as a Drawing
windows = Drawing()
building.windows = windows
rows = int(building_height // (0.4 * inches))
columns = int(building_width // (0.4 * inches))
for r in range(rows):
for c in range(columns):
# Create a small rectangle for each window
window = Rectangle(((-building_width / 2 + 0.2 * inches + c * 0.4 * inches),
(building_height / 2 - 0.2 * inches - r * 0.4 * inches)), 0.3 * inches, 0.3 * inches)
windows[f'window_{r}_{c}'] = window
return skyline
with AIDL_2D:
model = city_skyline()
print(model.Solve())
model.Render()
```
In this updated code:
1. Instead of using dictionary-style notation to add buildings to the `Assembly`, we use `setattr` to set each building as an attribute of the `skyline`.
2. Similarly, we use `setattr` to add window rectangles as attributes of the `windows` `Drawing`.
This should correctly add the buildings and windows to the skyline model. Let me know if there are any further issues or additional details you would like to add to the skyline!
Traceback (most recent call last):
File "/net/projects/ranalab/jz/aidl/AIDL/generation/backend.py", line 21, in dumbrun
exec(code, env)
File "", line 41, in
File "", line 35, in city_skyline
TypeError: 'Drawing' object does not support item assignment
Thank you for pointing that out. Attributes can't be assigned dynamically to `Drawing` nodes either. Instead, we'll need to create a named list of window objects for each `Drawing`.
Here's the corrected implementation:
```python
from AIDL import *
def city_skyline(building_count: int = 10, max_height: float = 8 * inches, min_height: float = 3 * inches, max_width: float = 1.5 * inches, min_width: float = 0.5 * inches):
"""
Model a simple city skyline with a given amount of buildings.
Each building will have random heights and widths within the specified ranges.
"""
# Random module for generating building dimensions
import random
skyline = Assembly()
for i in range(building_count):
building_height = random.uniform(min_height, max_height)
building_width = random.uniform(min_width, max_width)
building = Solid(shift=(i * (max_width + 0.2 * inches), 0)) # Add some spacing between buildings
building.body = Rectangle((0, building_height / 2), building_width, building_height)
setattr(skyline, f'building_{i}', building)
# Add window details as a Drawing
windows = Drawing()
building.windows = windows
rows = int(building_height // (0.4 * inches))
columns = int(building_width // (0.4 * inches))
windows.window_list = []
for r in range(rows):
for c in range(columns):
# Create a small rectangle for each window
window = Rectangle(((-building_width / 2 + 0.2 * inches + c * 0.4 * inches),
(building_height / 2 - 0.2 * inches - r * 0.4 * inches)), 0.3 * inches, 0.3 * inches)
windows.window_list.append(window)
return skyline
with AIDL_2D:
model = city_skyline()
print(model.Solve())
model.Render()
```
In this updated implementation:
1. We use `setattr` to assign each building to the `skyline`.
2. For windows, we create a list of windows called `window_list` and add each window rectangle to this list. The `Drawing` node's attribute `windows.window_list` will store all windows as objects that need to be engraved.
This should now work without issues. Let me know if there's anything else you need!
|