 |
CLIP Score: 24.9
from AIDL import *
def castle(
keep_width: float = 5 * inches,
keep_height: float = 10 * inches,
wall_length: float = 20 * inches,
wall_height: float = 5 * inches,
tower_radius: float = 2 * inches
):
"""
Model a simple castle with a central keep, surrounding walls, and corner towers.
"""
castle = Solid()
keep = Solid(shift=(0, 0))
walls = Solid()
towers = [Solid(shift=(wall_length/2, wall_length/2)),
Solid(shift=(-wall_length/2, wall_length/2)),
Solid(shift=(-wall_length/2, -wall_length/2)),
Solid(shift=(wall_length/2, -wall_length/2))]
castle.keep = keep
castle.walls = walls
castle.towers = {f"tower_{i}": tower for i, tower in enumerate(towers)}
# Define the keep geometry
keep.body = Rectangle((0,0), keep_width, keep_height)
# Define the wall geometry
walls.top = Line((-wall_length/2, wall_height/2), (wall_length/2, wall_height/2))
walls.bottom = Line((-wall_length/2, -wall_height/2), (wall_length/2, -wall_height/2))
walls.left = Line((-wall_length/2, -wall_height/2), (-wall_length/2, wall_height/2))
walls.right = Line((wall_length/2, -wall_height/2), (wall_length/2, wall_height/2))
# Define the corner tower geometry
for tower in towers:
tower.body = Circle((0,0), tower_radius)
# Compositional Constraints for keeping the walls and towers aligned
# Ensure the walls form a closed boundary around the keep
walls.AddConstraint(walls.top.length == wall_length)
walls.AddConstraint(walls.bottom.length == wall_length)
walls.AddConstraint(walls.left.length == wall_height)
walls.AddConstraint(walls.right.length == wall_height)
walls.AddConstraint(Coincident(walls.top.end, walls.right.end))
walls.AddConstraint(Coincident(walls.bottom.end, walls.right.start))
walls.AddConstraint(Coincident(walls.bottom.start, walls.left.start))
walls.AddConstraint(Coincident(walls.top.start, walls.left.end))
# Towers are at the corners of the walls
for idx, tower in enumerate(towers):
if idx == 0:
castle.AddConstraint(Coincident(tower.body.center, walls.top.end))
elif idx == 1:
castle.AddConstraint(Coincident(tower.body.center, walls.top.start))
elif idx == 2:
castle.AddConstraint(Coincident(tower.body.center, walls.bottom.start))
elif idx == 3:
castle.AddConstraint(Coincident(tower.body.center, walls.bottom.end))
# Add a hole for the entrance in the front wall (optional)
front_entrance = Hole()
front_entrance.door = Rectangle((0, -wall_height/2), keep_width/2, wall_height/3)
walls.front_entrance = front_entrance
walls.AddConstraint(Coincident(front_entrance.door.left.start, walls.bottom.midpoint))
return castle
with AIDL_2D:
model = castle()
print(model.Solve())
model.Render()
|
Please write an AIDL program to generate a castle
Sure! Let's start by defining the basic structure of the castle. For simplicity, let's focus on the main sections of the castle which include a central keep (main tower), surrounding walls, and corner towers.
### Step 1: Define the Structures and Their Hierarchical Relationships
We'll start by thinking about the main components of the castle:
1. **Keep**: The main tower in the center.
2. **Walls**: Surrounding the keep.
3. **Corner Towers**: Located at the corners of the walls.
### Step 2: Add Compositional Constraints to Position and Size the Structures
We will need to define constraints to position and size the structures relative to each other.
### Step 3: Define Geometry for Each Structure
We'll create the shapes for each part of the castle:
- **Keep**: A simple rectangle to represent the tower.
- **Walls**: Lines to form a square or rectangular boundary.
- **Corner Towers**: Circles or rounded rectangles at the corners of the walls.
### Step 4: Add Local Constraints for Each Structure
We'll ensure that each part maintains its shape and position as per our initial design.
Here is the AIDL program step by step to generate the castle:
```python
from AIDL import *
def castle(
keep_width: float = 5 * inches,
keep_height: float = 10 * inches,
wall_length: float = 20 * inches,
wall_height: float = 5 * inches,
tower_radius: float = 2 * inches
):
"""
Model a simple castle with a central keep, surrounding walls, and corner towers.
"""
castle = Solid()
keep = Solid(shift=(0, 0))
walls = Solid()
towers = [Solid(shift=(wall_length/2, wall_length/2)),
Solid(shift=(-wall_length/2, wall_length/2)),
Solid(shift=(-wall_length/2, -wall_length/2)),
Solid(shift=(wall_length/2, -wall_length/2))]
castle.keep = keep
castle.walls = walls
castle.towers = {f"tower_{i}": tower for i, tower in enumerate(towers)}
# Define the keep geometry
keep.body = Rectangle((0,0), keep_width, keep_height)
# Define the wall geometry
walls.top = Line((-wall_length/2, wall_height/2), (wall_length/2, wall_height/2))
walls.bottom = Line((-wall_length/2, -wall_height/2), (wall_length/2, -wall_height/2))
walls.left = Line((-wall_length/2, -wall_height/2), (-wall_length/2, wall_height/2))
walls.right = Line((wall_length/2, -wall_height/2), (wall_length/2, wall_height/2))
# Define the corner tower geometry
for tower in towers:
tower.body = Circle((0,0), tower_radius)
# Compositional Constraints for keeping the walls and towers aligned
# Ensure the walls form a closed boundary around the keep
walls.AddConstraint(walls.top.length == wall_length)
walls.AddConstraint(walls.bottom.length == wall_length)
walls.AddConstraint(walls.left.length == wall_height)
walls.AddConstraint(walls.right.length == wall_height)
walls.AddConstraint(Coincident(walls.top.end, walls.right.end))
walls.AddConstraint(Coincident(walls.bottom.end, walls.right.start))
walls.AddConstraint(Coincident(walls.bottom.start, walls.left.start))
walls.AddConstraint(Coincident(walls.top.start, walls.left.end))
# Towers are at the corners of the walls
for idx, tower in enumerate(towers):
if idx == 0:
castle.AddConstraint(Coincident(tower.body.center, walls.top.end))
elif idx == 1:
castle.AddConstraint(Coincident(tower.body.center, walls.top.start))
elif idx == 2:
castle.AddConstraint(Coincident(tower.body.center, walls.bottom.start))
elif idx == 3:
castle.AddConstraint(Coincident(tower.body.center, walls.bottom.end))
# Add a hole for the entrance in the front wall (optional)
front_entrance = Hole()
front_entrance.door = Rectangle((0, -wall_height/2), keep_width/2, wall_height/3)
walls.front_entrance = front_entrance
walls.AddConstraint(Coincident(front_entrance.door.left.start, walls.bottom.midpoint))
return castle
with AIDL_2D:
model = castle()
print(model.Solve())
model.Render()
```
### Explanation:
1. **castle Structure**: The main structure that holds everything.
2. **keep**: A simple rectangle representing the central tower.
3. **walls**: Lines forming a square/rectangle surrounding the keep.
4. **towers**: Circles at each corner of the wall.
5. **front_entrance**: An optional door hole to represent the entrance to the castle.
### Constraints:
- The walls form a closed boundary.
- Towers are placed at the corners of the walls.
- The keep is centrally positioned within the walls.
- Optional: Front entrance is centered along the bottom wall.
Feel free to modify the sizes and shapes of the components to better fit your design! If you need any further customization or additional features, let me know.
|