 |
CLIP Score: 29.46
from AIDL import *
def barn(length: float = 20*feet, width: float = 10*feet, height: float = 15*feet):
"""
Create a model of a barn with a rectangular body, a triangular roof,
a large door in the front, and four windows, two on each side.
"""
barn = Solid()
main_structure = Solid()
roof = Solid()
door = Hole()
windows = [Hole() for _ in range(4)]
roof_shingles = Drawing()
barn.main_structure = main_structure
barn.roof = roof
barn.door = door
barn.roof_shingles = roof_shingles
for i, window in enumerate(windows):
barn.__setattr__(f"window_{i+1}", window)
# Define the main body of the barn as a rectangle
main_structure.body = Rectangle((0, 0), length, height)
# Define the roof as an equilateral triangle on top of the main structure
roof.body = Triangle((0, height), length, width / 2)
# Position the roof on top of the main structure
barn.AddConstraint(roof.bb.bottom == main_structure.bb.top)
barn.AddConstraint(roof.bb.horizontal_center == main_structure.bb.horizontal_center)
# Define the door as a rectangle at the bottom center of the front face
door.frame = Rectangle((0, -height / 2 + 1*foot), length / 4, height / 2)
# Place the door on the front face
barn.AddConstraint(door.bb.horizontal_center == main_structure.bb.horizontal_center)
barn.AddConstraint(door.bb.bottom == main_structure.bb.bottom)
# Define the windows as smaller rectangles
for i, window in enumerate(windows):
window.frame = Rectangle((0, 0), length / 8, height / 6)
# Place the windows on the left and right sides of the barn
barn.AddConstraint(windows[0].bb.left == main_structure.bb.left + 1*foot)
barn.AddConstraint(windows[0].bb.vertical_center == main_structure.bb.vertical_center + 2*feet)
barn.AddConstraint(windows[1].bb.right == main_structure.bb.right - 1*foot)
barn.AddConstraint(windows[1].bb.vertical_center == main_structure.bb.vertical_center + 2*feet)
barn.AddConstraint(windows[2].bb.left == main_structure.bb.left + 1*foot)
barn.AddConstraint(windows[2].bb.vertical_center == main_structure.bb.vertical_center - 2*feet)
barn.AddConstraint(windows[3].bb.right == main_structure.bb.right - 1*foot)
barn.AddConstraint(windows[3].bb.vertical_center == main_structure.bb.vertical_center - 2*feet)
# Add roof shingles:
shingle_spacing = 1 * foot
roof_shingles.shingles = [Line((i*shingle_spacing, height), (i*shingle_spacing, height + (width/2))) for i in range(int(length/foot) + 1)]
for shingle in roof_shingles.shingles:
roof_shingles.AddConstraint(Vertical(shingle))
return barn
with AIDL_2D:
model = barn()
print(model.Solve())
model.Render()
|
Please write an AIDL program to generate a barn on a farm
Creating a barn involves several components, such as the main building structure, doors, windows, and possibly some additional architectural features. Let's break it down and create an AIDL program step-by-step.
Here's the conceptual plan for the barn:
1. **Main Structure:** A rectangular barn with a triangular roof.
2. **Doors:** A large rectangular door on the front.
3. **Windows:** Four rectangular windows, two on each side.
4. **Details:** Simple details like roof shingles engraved on the roof.
Let's start by defining the main structure and adding the necessary components.
### Step 1: Define the Main Structure
```python
from AIDL import *
def barn(length: float = 20*feet, width: float = 10*feet, height: float = 15*feet):
"""
Create a model of a barn with a rectangular body, a triangular roof,
a large door in the front, and four windows, two on each side.
"""
barn = Solid()
main_structure = Solid()
roof = Solid()
door = Hole()
windows = [Hole() for _ in range(4)]
barn.main_structure = main_structure
barn.roof = roof
barn.door = door
for i, window in enumerate(windows):
barn.__setattr__(f"window_{i+1}", window)
# Define the main body of the barn as a rectangle
main_structure.body = Rectangle((0, 0), length, height)
# Define the roof as an equilateral triangle on top of the main structure
roof.body = Triangle((0, height), length, width / 2)
# Position the roof on top of the main structure
barn.AddConstraint(roof.bb.bottom == main_structure.bb.top)
barn.AddConstraint(roof.bb.horizontal_center == main_structure.bb.horizontal_center)
# Define the door as a rectangle at the bottom center of the front face
door.frame = Rectangle((0, -height / 2 + 1*foot), length / 4, height / 2)
# Place the door on the front face
barn.AddConstraint(door.bb.horizontal_center == main_structure.bb.horizontal_center)
barn.AddConstraint(door.bb.bottom == main_structure.bb.bottom)
# Define the windows as smaller rectangles
for i, window in enumerate(windows):
window.frame = Rectangle((0, 0), length / 8, height / 6)
# Place the windows on the left and right sides of the barn
barn.AddConstraint(windows[0].bb.left == main_structure.bb.left + 1*foot)
barn.AddConstraint(windows[0].bb.vertical_center == main_structure.bb.vertical_center + 2*feet)
barn.AddConstraint(windows[1].bb.right == main_structure.bb.right - 1*foot)
barn.AddConstraint(windows[1].bb.vertical_center == main_structure.bb.vertical_center + 2*feet)
barn.AddConstraint(windows[2].bb.left == main_structure.bb.left + 1*foot)
barn.AddConstraint(windows[2].bb.vertical_center == main_structure.bb.vertical_center - 2*feet)
barn.AddConstraint(windows[3].bb.right == main_structure.bb.right - 1*foot)
barn.AddConstraint(windows[3].bb.vertical_center == main_structure.bb.vertical_center - 2*feet)
return barn
with AIDL_2D:
model = barn()
print(model.Solve())
model.Render()
```
### Step 2: Verify the Program and Add Details
Check if the primary structure and placements are rendered correctly. If all looks good, we can proceed with adding details like roof shingles.
### Step 3: Add Roof Shingles as Drawing Details
```python
from AIDL import *
def barn(length: float = 20*feet, width: float = 10*feet, height: float = 15*feet):
"""
Create a model of a barn with a rectangular body, a triangular roof,
a large door in the front, and four windows, two on each side.
"""
barn = Solid()
main_structure = Solid()
roof = Solid()
door = Hole()
windows = [Hole() for _ in range(4)]
roof_shingles = Drawing()
barn.main_structure = main_structure
barn.roof = roof
barn.door = door
barn.roof_shingles = roof_shingles
for i, window in enumerate(windows):
barn.__setattr__(f"window_{i+1}", window)
# Define the main body of the barn as a rectangle
main_structure.body = Rectangle((0, 0), length, height)
# Define the roof as an equilateral triangle on top of the main structure
roof.body = Triangle((0, height), length, width / 2)
# Position the roof on top of the main structure
barn.AddConstraint(roof.bb.bottom == main_structure.bb.top)
barn.AddConstraint(roof.bb.horizontal_center == main_structure.bb.horizontal_center)
# Define the door as a rectangle at the bottom center of the front face
door.frame = Rectangle((0, -height / 2 + 1*foot), length / 4, height / 2)
# Place the door on the front face
barn.AddConstraint(door.bb.horizontal_center == main_structure.bb.horizontal_center)
barn.AddConstraint(door.bb.bottom == main_structure.bb.bottom)
# Define the windows as smaller rectangles
for i, window in enumerate(windows):
window.frame = Rectangle((0, 0), length / 8, height / 6)
# Place the windows on the left and right sides of the barn
barn.AddConstraint(windows[0].bb.left == main_structure.bb.left + 1*foot)
barn.AddConstraint(windows[0].bb.vertical_center == main_structure.bb.vertical_center + 2*feet)
barn.AddConstraint(windows[1].bb.right == main_structure.bb.right - 1*foot)
barn.AddConstraint(windows[1].bb.vertical_center == main_structure.bb.vertical_center + 2*feet)
barn.AddConstraint(windows[2].bb.left == main_structure.bb.left + 1*foot)
barn.AddConstraint(windows[2].bb.vertical_center == main_structure.bb.vertical_center - 2*feet)
barn.AddConstraint(windows[3].bb.right == main_structure.bb.right - 1*foot)
barn.AddConstraint(windows[3].bb.vertical_center == main_structure.bb.vertical_center - 2*feet)
# Add roof shingles:
shingle_spacing = 1 * foot
roof_shingles.shingles = [Line((i*shingle_spacing, height), (i*shingle_spacing, height + (width/2))) for i in range(int(length/foot) + 1)]
for shingle in roof_shingles.shingles:
roof_shingles.AddConstraint(Vertical(shingle))
return barn
with AIDL_2D:
model = barn()
print(model.Solve())
model.Render()
```
### Step 4: Final Adjustments
You can run the above code to render the barn, check the placements and dimensions. Adjust the parameters and constraints as needed to improve the appearance and accuracy.
This should provide a good starting point for creating a barn model. Let me know if you need any further adjustments or additions!
|