 |
CLIP Score: 22.88
from AIDL import *
def butterfly(
body_height: float = 2 * inches,
body_width: float = 0.5 * inches,
wing_span: float = 4 * inches,
wing_height: float = 2 * inches,
wing_corners_radius: float = 0.3 * inches,
decorative_hole_radius: float = 0.2 * inches,
):
"""
Model a simple butterfly with a body and two pairs of wings with decorative holes.
"""
# Define the model structure. The butterfly's main structure is an Assembly
butterfly = Assembly()
body = Solid()
left_upper_wing = Solid(shift=(-wing_span/2, body_height/2))
right_upper_wing = Solid(shift=(wing_span/2, body_height/2))
left_lower_wing = Solid(shift=(-wing_span/2, -body_height/2))
right_lower_wing = Solid(shift=(wing_span/2, -body_height/2))
# Add the components to the butterfly
butterfly.body = body
butterfly.left_upper_wing = left_upper_wing
butterfly.right_upper_wing = right_upper_wing
butterfly.left_lower_wing = left_lower_wing
butterfly.right_lower_wing = right_lower_wing
# Define the body geometry
body.shape = RoundedRectangle((0, 0), body_width, body_height, corner_radius=body_width / 2)
# Define the wings geometry
left_upper_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
right_upper_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
left_lower_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
right_lower_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
# Add decorative holes to the wings
decorative_holes = [
(0, 0.5 * wing_height),
(0, -0.5 * wing_height),
(-0.25 * wing_span / 2, 0),
(0.25 * wing_span / 2, 0)
]
for i, (dx, dy) in enumerate(decorative_holes):
for wing in [left_upper_wing, right_upper_wing, left_lower_wing, right_lower_wing]:
hole = Hole()
hole.circle = Circle((dx, dy), decorative_hole_radius)
setattr(wing, f"hole_{i}", hole)
return butterfly
with AIDL_2D:
model = butterfly()
print(model.Solve())
model.Render()
|
Please write an AIDL program to generate a butterfly
Sure, let's create a model of a butterfly using the AIDL language. We'll start with a high-level plan for the butterfly structure, which will include:
1. **Body:** The main body of the butterfly.
2. **Wings:** The left and right wings which will have a rounded edge and some decorative holes.
Here's a step-by-step breakdown:
1. **Main Body:** This will be a simple rounded rectangle representing the butterfly's thorax and abdomen.
2. **Wings:** Two pairs of wings (upper and lower for both left and right sides).
3. **Decorative Holes:** Add some decorative holes to the wings.
Let's go ahead and create the function and add the necessary structures.
```python
from AIDL import *
def butterfly(
body_height: float = 2 * inches,
body_width: float = 0.5 * inches,
wing_span: float = 4 * inches,
wing_height: float = 2 * inches,
wing_corners_radius: float = 0.3 * inches,
decorative_hole_radius: float = 0.2 * inches,
):
"""
Model a simple butterfly with a body and two pairs of wings with decorative holes.
"""
# Define the model structure. The butterfly's main structure is an Assembly
butterfly = Assembly()
body = Solid()
left_upper_wing = Solid(shift=(-wing_span/2, body_height/2))
right_upper_wing = Solid(shift=(wing_span/2, body_height/2))
left_lower_wing = Solid(shift=(-wing_span/2, -body_height/2))
right_lower_wing = Solid(shift=(wing_span/2, -body_height/2))
# Add the components to the butterfly
butterfly.body = body
butterfly.left_upper_wing = left_upper_wing
butterfly.right_upper_wing = right_upper_wing
butterfly.left_lower_wing = left_lower_wing
butterfly.right_lower_wing = right_lower_wing
# Define the body geometry
body.shape = RoundedRectangle((0, 0), body_width, body_height, radius=body_width / 2)
# Define the wings geometry
left_upper_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
right_upper_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
left_lower_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
right_lower_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
# Add decorative holes to the wings
decorative_holes = [
(0, 0.5 * wing_height),
(0, -0.5 * wing_height),
(-0.25 * wing_span, 0),
(0.25 * wing_span, 0)
]
for i, (dx, dy) in enumerate(decorative_holes):
for wing in [left_upper_wing, right_upper_wing, left_lower_wing, right_lower_wing]:
hole_center = (dx, dy)
getattr(wing, f"hole_{i}") = Hole()
getattr(wing, f"hole_{i}").circle = Circle(hole_center, decorative_hole_radius)
return butterfly
with AIDL_2D:
model = butterfly()
print(model.Solve())
model.Render()
```
This code creates a butterfly model with a simplified body and wings, along with some decorative holes in the wings. You can adjust the dimensions by modifying the function parameters.
Please let me know if you need any changes or additional features!
Traceback (most recent call last):
File "/net/projects/ranalab/jz/aidl/AIDL/generation/backend.py", line 21, in dumbrun
exec(code, env)
File "", line 51
getattr(wing, f"hole_{i}") = Hole()
^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
It looks like there's an issue with setting attributes using `getattr`. Python does not support using `getattr` for assignment directly. We should use `setattr` instead.
Here's the corrected code:
```python
from AIDL import *
def butterfly(
body_height: float = 2 * inches,
body_width: float = 0.5 * inches,
wing_span: float = 4 * inches,
wing_height: float = 2 * inches,
wing_corners_radius: float = 0.3 * inches,
decorative_hole_radius: float = 0.2 * inches,
):
"""
Model a simple butterfly with a body and two pairs of wings with decorative holes.
"""
# Define the model structure. The butterfly's main structure is an Assembly
butterfly = Assembly()
body = Solid()
left_upper_wing = Solid(shift=(-wing_span/2, body_height/2))
right_upper_wing = Solid(shift=(wing_span/2, body_height/2))
left_lower_wing = Solid(shift=(-wing_span/2, -body_height/2))
right_lower_wing = Solid(shift=(wing_span/2, -body_height/2))
# Add the components to the butterfly
butterfly.body = body
butterfly.left_upper_wing = left_upper_wing
butterfly.right_upper_wing = right_upper_wing
butterfly.left_lower_wing = left_lower_wing
butterfly.right_lower_wing = right_lower_wing
# Define the body geometry
body.shape = RoundedRectangle((0, 0), body_width, body_height, corner_radius=body_width / 2)
# Define the wings geometry
left_upper_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
right_upper_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
left_lower_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
right_lower_wing.shape = RoundedRectangle((0, 0), wing_span / 2, wing_height, corner_radius=wing_corners_radius)
# Add decorative holes to the wings
decorative_holes = [
(0, 0.5 * wing_height),
(0, -0.5 * wing_height),
(-0.25 * wing_span / 2, 0),
(0.25 * wing_span / 2, 0)
]
for i, (dx, dy) in enumerate(decorative_holes):
for wing in [left_upper_wing, right_upper_wing, left_lower_wing, right_lower_wing]:
hole = Hole()
hole.circle = Circle((dx, dy), decorative_hole_radius)
setattr(wing, f"hole_{i}", hole)
return butterfly
with AIDL_2D:
model = butterfly()
print(model.Solve())
model.Render()
```
I've updated the code to use `setattr` for assigning the decorative hole attributes to each wing. This should work correctly now. Please run it and see if it resolves the problem. If you encounter any other issues, let me know!
|