 |
CLIP Score: 30.01
from AIDL import *
def fancy_teapot(
body_radius: float = 4 * inches,
body_height: float = 6 * inches,
spout_length: float = 4 * inches,
handle_height: float = 3 * inches,
handle_width: float = 0.5 * inches,
lid_radius: float = 2 * inches,
lid_height: float = 1 * inch
):
"""
Model a fancy teapot with a rounded body, a spout, a handle, and a lid.
"""
# Main structure of the teapot
teapot = Solid()
# Parts of the teapot
teapot.body = Solid()
teapot.lid = Solid()
teapot.spout = Solid()
teapot.handle = Solid()
# Constraint relationships between the parts:
# Make the lid sit directly on top of the body
teapot.AddConstraint(teapot.lid.bb.bottom == teapot.body.bb.top)
# Ensure the spout is vertically centered relative to the body's origin
teapot.AddConstraint(teapot.spout.bb.horizontal_center == teapot.body.bb.right)
teapot.AddConstraint(teapot.spout.bb.vertical_center == teapot.body.bb.vertical_center)
# Horizontally align the handle with the body's origin
teapot.AddConstraint(teapot.handle.bb.left == teapot.body.bb.left)
teapot.AddConstraint(teapot.handle.bb.vertical_center == teapot.body.bb.vertical_center)
# Geometry for the body (a rounded rectangle)
teapot.body.shape = RoundedRectangle((0, 0), 2 * body_radius, body_height, body_radius / 2)
# Geometry for the lid (a circle) and its handle (decorative circle on top)
teapot.lid.shape = Circle((0, 0), lid_radius)
teapot.lid.handle = Circle((0, lid_height / 2), lid_radius / 2)
# Geometry for the spout (a rectangle with one rounded end, represented using Arcs)
spout_shift = (body_radius + spout_length / 2, 0)
teapot.spout.main_body = Rectangle(spout_shift, spout_length, body_radius / 2)
teapot.spout.round_end = Arc(spout_shift, -90, 90, body_radius / 2)
# Geometry for the handle (a rectangle for the main part and an Arc for the curved top)
handle_shift = (-handle_width / 2, 0)
teapot.handle.main_body = Rectangle(handle_shift, handle_width, handle_height)
teapot.handle.curve = Arc((handle_width, 0), -90, 90, handle_height / 2)
return teapot
with AIDL_2D:
model = fancy_teapot()
print(model.Solve())
model.Render()
|
Please write an AIDL program to generate a fancy teapot
Sure! Let's start by breaking down the components of a fancy teapot. A typical teapot consists of the following parts:
1. **Body**: The main container that holds the tea.
2. **Lid**: The cover that goes on top of the body.
3. **Spout**: The part through which tea is poured.
4. **Handle**: The part used to lift and pour the teapot.
With these components in mind, let's proceed step-by-step:
1. **Define the structures and their hierarchical relationships**.
2. **Add constraints between the structures**.
3. **Define the geometry for each structure**.
Let's start with step 1.
### Step 1: Define the Structures and Their Hierarchical Relationships
```python
from AIDL import *
def fancy_teapot(
body_radius: float = 4 * inches,
body_height: float = 6 * inches,
spout_length: float = 4 * inches,
handle_height: float = 3 * inches,
handle_width: float = 0.5 * inches,
lid_radius: float = 2 * inches,
lid_height: float = 1 * inch
):
"""
Model a fancy teapot with a rounded body, a spout, a handle, and a lid.
"""
# Main structure of the teapot
teapot = Solid()
# Parts of the teapot
teapot.body = Solid()
teapot.lid = Solid()
teapot.spout = Solid()
teapot.handle = Solid()
return teapot
with AIDL_2D:
model = fancy_teapot()
print(model.Solve())
model.Render()
```
### Step 2: Add Constraints Between the Structures
```python
from AIDL import *
def fancy_teapot(
body_radius: float = 4 * inches,
body_height: float = 6 * inches,
spout_length: float = 4 * inches,
handle_height: float = 3 * inches,
handle_width: float = 0.5 * inches,
lid_radius: float = 2 * inches,
lid_height: float = 1 * inch
):
"""
Model a fancy teapot with a rounded body, a spout, a handle, and a lid.
"""
# Main structure of the teapot
teapot = Solid()
# Parts of the teapot
teapot.body = Solid()
teapot.lid = Solid()
teapot.spout = Solid()
teapot.handle = Solid()
# Constraint relationships between the parts:
# Make the lid sit directly on top of the body
teapot.AddConstraint(teapot.lid.bb.bottom == teapot.body.bb.top)
# Ensure the spout is vertically centered relative to the body's origin
teapot.AddConstraint(teapot.spout.bb.horizontal_center == teapot.body.bb.right)
teapot.AddConstraint(teapot.spout.bb.vertical_center == teapot.body.bb.vertical_center)
# Horizontally align the handle with the body's origin
teapot.AddConstraint(teapot.handle.bb.left == teapot.body.bb.left)
teapot.AddConstraint(teapot.handle.bb.vertical_center == teapot.body.bb.vertical_center)
return teapot
with AIDL_2D:
model = fancy_teapot()
print(model.Solve())
model.Render()
```
### Step 3: Define the Geometry for Each Structure
Let's define the geometric shapes for the body, lid, spout, and handle.
```python
from AIDL import *
def fancy_teapot(
body_radius: float = 4 * inches,
body_height: float = 6 * inches,
spout_length: float = 4 * inches,
handle_height: float = 3 * inches,
handle_width: float = 0.5 * inches,
lid_radius: float = 2 * inches,
lid_height: float = 1 * inch
):
"""
Model a fancy teapot with a rounded body, a spout, a handle, and a lid.
"""
# Main structure of the teapot
teapot = Solid()
# Parts of the teapot
teapot.body = Solid()
teapot.lid = Solid()
teapot.spout = Solid()
teapot.handle = Solid()
# Constraint relationships between the parts:
# Make the lid sit directly on top of the body
teapot.AddConstraint(teapot.lid.bb.bottom == teapot.body.bb.top)
# Ensure the spout is vertically centered relative to the body's origin
teapot.AddConstraint(teapot.spout.bb.horizontal_center == teapot.body.bb.right)
teapot.AddConstraint(teapot.spout.bb.vertical_center == teapot.body.bb.vertical_center)
# Horizontally align the handle with the body's origin
teapot.AddConstraint(teapot.handle.bb.left == teapot.body.bb.left)
teapot.AddConstraint(teapot.handle.bb.vertical_center == teapot.body.bb.vertical_center)
# Geometry for the body (a rounded rectangle)
teapot.body.shape = RoundedRectangle((0, 0), 2 * body_radius, body_height, body_radius / 2)
# Geometry for the lid (a circle) and its handle (decorative circle on top)
teapot.lid.shape = Circle((0, 0), lid_radius)
teapot.lid.handle = Circle((0, lid_height / 2), lid_radius / 2)
# Geometry for the spout (a rectangle with one rounded end, represented using Arcs)
spout_shift = (body_radius + spout_length / 2, 0)
teapot.spout.main_body = Rectangle(spout_shift, spout_length, body_radius / 2)
teapot.spout.round_end = Arc(spout_shift, -90, 90, body_radius / 2)
# Geometry for the handle (a rectangle for the main part and an Arc for the curved top)
handle_shift = (-handle_width / 2, 0)
teapot.handle.main_body = Rectangle(handle_shift, handle_width, handle_height)
teapot.handle.curve = Arc((handle_width, 0), -90, 90, handle_height / 2)
return teapot
with AIDL_2D:
model = fancy_teapot()
print(model.Solve())
model.Render()
```
This should generate the geometry for a fancy teapot with a rounded body, spout, and handle, as well as a lid with a decorative handle on top. Let me know if you have any specific adjustments or additional features you'd like to include!
|