 |
CLIP Score: 26.88
from AIDL import *
# Define the inches unit as a multiplier
inch = 1
def vintage_camera(
body_width: float = 6 * inch,
body_height: float = 4 * inch,
body_depth: float = 2 * inch,
lens_radius: float = 1.5 * inch,
button_radius: float = 0.3 * inch,
viewfinder_width: float = 1 * inch,
viewfinder_height: float = 0.5 * inch,
flash_width: float = 1.5 * inch,
flash_height: float = 0.5 * inch):
"""
Create a vintage camera model.
"""
# Main body of the camera
camera = Solid()
camera.body = Rectangle((0, 0), body_width, body_height)
# Lens of the camera
lens_shift_x = 0
lens_shift_y = 0 # Centered vertically on the body
camera.lens = Solid(shift=(lens_shift_x, lens_shift_y))
camera.lens.disk = Circle((0, 0), lens_radius)
# Shutter button
button_shift_x = body_width / 2 - button_radius - 0.2 * inch
button_shift_y = body_height / 2 - button_radius - 0.2 * inch
camera.button = Solid(shift=(-button_shift_x, button_shift_y))
camera.button.disk = Circle((0, 0), button_radius)
# Viewfinder
viewfinder_shift_x = body_width / 2 - viewfinder_width / 2 - 0.5 * inch
viewfinder_shift_y = body_height / 2 - viewfinder_height / 2 + body_height / 4
camera.viewfinder = Solid(shift=(viewfinder_shift_x, viewfinder_shift_y))
camera.viewfinder.rect = Rectangle((0, 0), viewfinder_width, viewfinder_height)
# Flash
flash_shift_x = -body_width / 3
flash_shift_y = body_height / 2 - flash_height / 2
camera.flash = Solid(shift=(flash_shift_x, flash_shift_y))
camera.flash.rect = Rectangle((0, 0), flash_width, flash_height)
return camera
with AIDL_2D:
model = vintage_camera()
print(model.Solve())
model.Render()
|
Please write an AIDL program to generate a vintage camera
Sure! Let's break down the task of creating a 2D CAD model of a vintage camera step-by-step. I'll outline the plan for the model first:
1. **Main Body**: The main rectangular body of the camera.
2. **Lens**: The circular lens at the front.
3. **Shutter Button**: A circular button at the top.
4. **Viewfinder**: A small rectangle on the top or side of the camera.
5. **Flash**: A smaller rectangle on the front of the camera.
Let's start step-by-step:
### Step 1: Set up the model structure and main body
We'll create the main body rectangle as a `Solid`, which will form the base structure of our camera.
```python
from AIDL import *
def vintage_camera(body_width: float = 6*inches, body_height: float = 4*inches, body_depth: float = 2*inches):
"""
Create a vintage camera model.
"""
# Main body of the camera
camera = Solid()
camera.body = Rectangle((0, 0), body_width, body_height)
return camera
```
### Step 2: Add the lens
We'll add a circular lens as a `Solid` on the front of the camera body.
```python
def vintage_camera(body_width: float = 6*inches, body_height: float = 4*inches, body_depth: float = 2*inches, lens_radius: float = 1.5*inches):
"""
Create a vintage camera model.
"""
# Main body of the camera
camera = Solid()
camera.body = Rectangle((0, 0), body_width, body_height)
# Lens of the camera
lens_shift_x = 0
lens_shift_y = 0 # Centered vertically on the body
camera.lens = Solid(shift=(lens_shift_x, lens_shift_y))
camera.lens.disk = Circle((0, 0), lens_radius)
return camera
```
### Step 3: Add the shutter button
We'll add a shutter button as a small circle at the top of the camera body.
```python
def vintage_camera(body_width: float = 6*inches, body_height: float = 4*inches, body_depth: float = 2*inches, lens_radius: float = 1.5*inches, button_radius: float = 0.3*inches):
"""
Create a vintage camera model.
"""
# Main body of the camera
camera = Solid()
camera.body = Rectangle((0, 0), body_width, body_height)
# Lens of the camera
lens_shift_x = 0
lens_shift_y = 0 # Centered vertically on the body
camera.lens = Solid(shift=(lens_shift_x, lens_shift_y))
camera.lens.disk = Circle((0, 0), lens_radius)
# Shutter button
button_shift_x = body_width / 2 - button_radius - 0.2*inches
button_shift_y = body_height / 2 - button_radius - 0.2*inches
camera.button = Solid(shift=(-button_shift_x, button_shift_y))
camera.button.disk = Circle((0, 0), button_radius)
return camera
```
### Step 4: Add the viewfinder
We'll add a smaller rectangle at the top right or side of the camera body as the viewfinder.
```python
def vintage_camera(body_width: float = 6*inches, body_height: float = 4*inches, body_depth: float = 2*inches, lens_radius: float = 1.5*inches, button_radius: float = 0.3*inches, viewfinder_width: float = 1*inch, viewfinder_height: float = 0.5*inch):
"""
Create a vintage camera model.
"""
# Main body of the camera
camera = Solid()
camera.body = Rectangle((0, 0), body_width, body_height)
# Lens of the camera
lens_shift_x = 0
lens_shift_y = 0 # Centered vertically on the body
camera.lens = Solid(shift=(lens_shift_x, lens_shift_y))
camera.lens.disk = Circle((0, 0), lens_radius)
# Shutter button
button_shift_x = body_width / 2 - button_radius - 0.2*inches
button_shift_y = body_height / 2 - button_radius - 0.2*inches
camera.button = Solid(shift=(-button_shift_x, button_shift_y))
camera.button.disk = Circle((0, 0), button_radius)
# Viewfinder
viewfinder_shift_x = body_width / 2 - viewfinder_width / 2 - 0.5*inch
viewfinder_shift_y = body_height / 2 - viewfinder_height / 2 + body_height / 4
camera.viewfinder = Solid(shift=(viewfinder_shift_x, viewfinder_shift_y))
camera.viewfinder.rect = Rectangle((0, 0), viewfinder_width, viewfinder_height)
return camera
```
### Step 5: Add the flash
We'll add a smaller rectangle at the front of the camera body as the flash.
```python
def vintage_camera(body_width: float = 6*inches, body_height: float = 4*inches, body_depth: float = 2*inches, lens_radius: float = 1.5*inches, button_radius: float = 0.3*inches, viewfinder_width: float = 1*inch, viewfinder_height: float = 0.5*inch, flash_width: float = 1.5*inches, flash_height: float = 0.5*inch):
"""
Create a vintage camera model.
"""
# Main body of the camera
camera = Solid()
camera.body = Rectangle((0, 0), body_width, body_height)
# Lens of the camera
lens_shift_x = 0
lens_shift_y = 0 # Centered vertically on the body
camera.lens = Solid(shift=(lens_shift_x, lens_shift_y))
camera.lens.disk = Circle((0, 0), lens_radius)
# Shutter button
button_shift_x = body_width / 2 - button_radius - 0.2*inches
button_shift_y = body_height / 2 - button_radius - 0.2*inches
camera.button = Solid(shift=(-button_shift_x, button_shift_y))
camera.button.disk = Circle((0, 0), button_radius)
# Viewfinder
viewfinder_shift_x = body_width / 2 - viewfinder_width / 2 - 0.5*inch
viewfinder_shift_y = body_height / 2 - viewfinder_height / 2 + body_height / 4
camera.viewfinder = Solid(shift=(viewfinder_shift_x, viewfinder_shift_y))
camera.viewfinder.rect = Rectangle((0, 0), viewfinder_width, viewfinder_height)
# Flash
flash_shift_x = -body_width / 3
flash_shift_y = body_height / 2 - flash_height/2
camera.flash = Solid(shift=(flash_shift_x, flash_shift_y))
camera.flash.rect = Rectangle((0, 0), flash_width, flash_height)
return camera
```
Now let's render it:
```python
with AIDL_2D:
model = vintage_camera()
print(model.Solve())
model.Render()
```
This completes the basic structure of a vintage camera. Feel free to add more details or modify its dimensions to match your exact requirements. 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 2, in
NameError: name 'inches' is not defined
Ah, I see the issue. The `inches` unit needs to be defined in your script. Let's define it at the beginning of the script. We should also adjust our code to ensure values are correctly defined. Here’s the revised script:
```python
from AIDL import *
# Define the inches unit as a multiplier
inch = 1
def vintage_camera(
body_width: float = 6 * inch,
body_height: float = 4 * inch,
body_depth: float = 2 * inch,
lens_radius: float = 1.5 * inch,
button_radius: float = 0.3 * inch,
viewfinder_width: float = 1 * inch,
viewfinder_height: float = 0.5 * inch,
flash_width: float = 1.5 * inch,
flash_height: float = 0.5 * inch):
"""
Create a vintage camera model.
"""
# Main body of the camera
camera = Solid()
camera.body = Rectangle((0, 0), body_width, body_height)
# Lens of the camera
lens_shift_x = 0
lens_shift_y = 0 # Centered vertically on the body
camera.lens = Solid(shift=(lens_shift_x, lens_shift_y))
camera.lens.disk = Circle((0, 0), lens_radius)
# Shutter button
button_shift_x = body_width / 2 - button_radius - 0.2 * inch
button_shift_y = body_height / 2 - button_radius - 0.2 * inch
camera.button = Solid(shift=(-button_shift_x, button_shift_y))
camera.button.disk = Circle((0, 0), button_radius)
# Viewfinder
viewfinder_shift_x = body_width / 2 - viewfinder_width / 2 - 0.5 * inch
viewfinder_shift_y = body_height / 2 - viewfinder_height / 2 + body_height / 4
camera.viewfinder = Solid(shift=(viewfinder_shift_x, viewfinder_shift_y))
camera.viewfinder.rect = Rectangle((0, 0), viewfinder_width, viewfinder_height)
# Flash
flash_shift_x = -body_width / 3
flash_shift_y = body_height / 2 - flash_height / 2
camera.flash = Solid(shift=(flash_shift_x, flash_shift_y))
camera.flash.rect = Rectangle((0, 0), flash_width, flash_height)
return camera
with AIDL_2D:
model = vintage_camera()
print(model.Solve())
model.Render()
```
This script includes the definition for `inch` and should run without throwing the `NameError`. Try running this revised script, and let me know if it works or if you encounter any other errors!
|