 |
CLIP Score: 29.1
from AIDL import *
def fountain_pen(
total_length: float = 6 * inches,
barrel_diameter: float = 0.5 * inch,
section_length: float = 1.5 * inch,
nib_length: float = 1 * inch,
cap_length: float = 2 * inches):
# Create the root structure for the pen
pen = Solid()
# Add substructures for barrel, section, nib, and cap
pen.barrel = Solid()
pen.section = Solid(shift=(0, -section_length)) # Shift to align with the barrel
pen.nib = Solid(shift=(0, -(section_length + nib_length)))
pen.cap = Solid(shift=(0, cap_length))
# Barrel Geometry
pen.barrel.body = RoundedRectangle((0, 0), barrel_diameter, total_length - section_length - nib_length, barrel_diameter / 4)
# Section Geometry
pen.section.body = RoundedRectangle((0, 0), barrel_diameter - 0.1*inch, section_length, (barrel_diameter - 0.1*inch)/4)
# Nib Geometry
pen.nib.body = Triangle((0, 0), barrel_diameter - 0.2*inch, nib_length)
# Cap Geometry
pen.cap.body = RoundedRectangle((0, 0), barrel_diameter + 0.05*inch, cap_length, (barrel_diameter + 0.05*inch)/4)
# Constraints
# Ensure the nib is properly aligned at the tip
pen.AddConstraint(pen.nib.bb.bottom == pen.section.bb.top)
pen.AddConstraint(pen.nib.bb.horizontal_center == pen.section.bb.horizontal_center)
# Ensure the section is aligned with the barrel
pen.AddConstraint(pen.section.bb.bottom == pen.barrel.bb.top)
pen.AddConstraint(pen.section.bb.horizontal_center == pen.barrel.bb.horizontal_center)
# Ensure the cap is properly positioned
pen.AddConstraint(pen.cap.bb.top == pen.barrel.bb.top)
pen.AddConstraint(pen.cap.bb.horizontal_center == pen.barrel.bb.horizontal_center)
return pen
with AIDL_2D:
model = fountain_pen()
print(model.Solve())
model.Render()
|
Please write an AIDL program to generate a fountain pen
Sure! Let's break down the process to design a fountain pen using AIDL. We'll start by outlining the main components of a fountain pen and decide on the hierarchical structure.
A typical fountain pen consists of:
1. The barrel (main body of the pen).
2. The section (the part you hold while writing).
3. The nib (where ink touches the paper).
4. The cap (which covers the nib when not in use).
**Steps:**
1. Create the main structure of the pen (Solid).
2. Define each substructure for the barrel, section, nib, and cap.
3. Define the geometric features and constraints for each substructure.
Let's start:
```python
from AIDL import *
def fountain_pen(
total_length: float = 6 * inches,
barrel_diameter: float = 0.5 * inch,
section_length: float = 1.5 * inch,
nib_length: float = 1 * inch,
cap_length: float = 2 * inches):
# Create the root structure for the pen
pen = Solid()
# Add substructures for barrel, section, nib, and cap
pen.barrel = Solid()
pen.section = Solid(shift=(0, -section_length)) # Shift to align with the barrel
pen.nib = Solid(shift=(0, -(section_length + nib_length)))
pen.cap = Solid(shift=(0, cap_length))
# Barrel Geometry
pen.barrel.body = RoundedRectangle((0, 0), barrel_diameter, total_length - section_length - nib_length, barrel_diameter / 4)
# Section Geometry
pen.section.body = RoundedRectangle((0, 0), barrel_diameter - 0.1*inch, section_length, (barrel_diameter - 0.1*inch)/4)
# Nib Geometry
pen.nib.body = Triangle((0, 0), barrel_diameter - 0.2*inch, nib_length)
# Cap Geometry
pen.cap.body = RoundedRectangle((0, 0), barrel_diameter + 0.05*inch, cap_length, (barrel_diameter + 0.05*inch)/4)
# Constraints
# Ensure the nib is properly aligned at the tip
pen.AddConstraint(pen.nib.bb.bottom == pen.section.bb.top)
pen.AddConstraint(pen.nib.bb.horizontal_center == pen.section.bb.horizontal_center)
# Ensure the section is aligned with the barrel
pen.AddConstraint(pen.section.bb.bottom == pen.barrel.bb.top)
pen.AddConstraint(pen.section.bb.horizontal_center == pen.barrel.bb.horizontal_center)
# Ensure the cap is properly positioned
pen.AddConstraint(pen.cap.bb.top == pen.barrel.bb.top)
pen.AddConstraint(pen.cap.bb.horizontal_center == pen.barrel.bb.horizontal_center)
return pen
with AIDL_2D:
model = fountain_pen()
print(model.Solve())
model.Render()
```
### Explanation
1. **Structure Definition:**
- `pen` is the root `Solid` structure.
- Substructures `pen.barrel`, `pen.section`, `pen.nib`, and `pen.cap` are created and positioned.
2. **Geometry Definition:**
- Barrel: Defined using `RoundedRectangle` and sized appropriately.
- Section: Slightly smaller in diameter and placed below the barrel.
- Nib: Represented as a `Triangle` for simplicity and positioned at the end of the section.
- Cap: Positioned above the barrel and slightly larger in diameter.
3. **Constraints:**
- Align and position each component correctly relative to each other.
This program generates a basic outline of a fountain pen using AIDL. You can add more details and constraints as needed to match any specific design requirements. Let me know if you need further customization or any additional features!
|