## aidl/sunglasses/sunglasses3

### Image | ### Program | ### Conversation

###
CLIP Score: 25.02

    from AIDL import *

    def sunglasses(
        lens_radius: float = 1 * inch,
        frame_thickness: float = 0.1 * inch,
        bridge_width: float = 0.5 * inch,
        temple_length: float = 4 * inch,
        temple_width: float = 0.25 * inch
    ):
        sunglasses = Assembly()
        frame = Solid()
        left_lens = Solid()
        right_lens = Solid()
        left_temple = Solid()
        right_temple = Solid()
        bridge = Solid()

        sunglasses.frame = frame
        frame.left_lens = left_lens
        frame.right_lens = right_lens
        frame.bridge = bridge
        sunglasses.left_temple = left_temple
        sunglasses.right_temple = right_temple

        # Frame constraints
        frame.AddConstraint(left_lens.bb.horizontal_center == -bridge_width / 2)
        frame.AddConstraint(right_lens.bb.horizontal_center == bridge_width / 2)
        frame.AddConstraint(left_lens.bb.vertical_center == 0)
        frame.AddConstraint(right_lens.bb.vertical_center == 0)
        frame.AddConstraint(bridge.bb.horizontal_center == 0)
        frame.AddConstraint(bridge.bb.vertical_center == 0)

        # Temples constraints
        sunglasses.AddConstraint(left_temple.bb.vertical_center == left_lens.bb.vertical_center)
        sunglasses.AddConstraint(right_temple.bb.vertical_center == right_lens.bb.vertical_center)
        sunglasses.AddConstraint(left_temple.bb.left == left_lens.bb.right + frame_thickness)
        sunglasses.AddConstraint(right_temple.bb.right == right_lens.bb.left - frame_thickness)

        # Geometry
        left_lens.geometry = Circle((0,0), lens_radius)
        right_lens.geometry = Circle((0,0), lens_radius)
        bridge.geometry = Rectangle((0,0), bridge_width, frame_thickness)

        left_temple.geometry = Rectangle((0,0), temple_length, temple_width)
        right_temple.geometry = Rectangle((0,0), temple_length, temple_width)

        # Frame geometry
        left_lens_frame = RoundedRectangle((0,0), 2 * lens_radius + frame_thickness, 2 * lens_radius + frame_thickness, frame_thickness / 2)
        right_lens_frame = RoundedRectangle((0,0), 2 * lens_radius + frame_thickness, 2 * lens_radius + frame_thickness, frame_thickness / 2)
        frame.left_frame = left_lens_frame
        frame.right_frame = right_lens_frame

        frame.AddConstraint(Coincident(left_lens.geometry.center, left_lens_frame.center))
        frame.AddConstraint(Coincident(right_lens.geometry.center, right_lens_frame.center))

        return sunglasses

    with AIDL_2D:
        model = sunglasses()
    print(model.Solve())
    model.Render()
                    Please write an AIDL program to generate a sunglasses

    Sure! Let's break down the process of generating the model for sunglasses into several steps. We'll start by creating the main structure and then add details on top of it.

    ### Step 1: Define Structures

    Let's start by defining the main structures and their hierarchical relationships. For sunglasses, we typically have the following parts:

    1. Frame
    2. Left Lens
    3. Right Lens
    4. Bridge (connecting the left and right lenses)
    5. Temples (arms of the sunglasses)

    Here's the structure definition:

    ```python
    from AIDL import *

    def sunglasses(
        lens_radius: float = 1 * inch,
        frame_thickness: float = 0.1 * inch,
        bridge_width: float = 0.5 * inch,
        temple_length: float = 4 * inch,
        temple_width: float = 0.25 * inch
    ):
        sunglasses = Assembly()
        frame = Solid()
        left_lens = Solid()
        right_lens = Solid()
        left_temple = Solid()
        right_temple = Solid()
        bridge = Solid()

        sunglasses.frame = frame
        frame.left_lens = left_lens
        frame.right_lens = right_lens
        frame.bridge = bridge
        sunglasses.left_temple = left_temple
        sunglasses.right_temple = right_temple

        # Hierarchy: frame contains both lenses and the bridge
        # sunglasses contains the frame and the temples
        return sunglasses

    with AIDL_2D:
        model = sunglasses()
    print(model.Solve())
    model.Render()
    ```

    ### Step 2: Add Constraints

    Next, we need to add constraints to ensure the parts are properly positioned and sized. We'll keep the lenses symmetrically aligned and attach the bridge between them. The temples will be aligned with the lenses.

    ```python
    from AIDL import *

    def sunglasses(
        lens_radius: float = 1 * inch,
        frame_thickness: float = 0.1 * inch,
        bridge_width: float = 0.5 * inch,
        temple_length: float = 4 * inch,
        temple_width: float = 0.25 * inch
    ):
        sunglasses = Assembly()
        frame = Solid()
        left_lens = Solid()
        right_lens = Solid()
        left_temple = Solid()
        right_temple = Solid()
        bridge = Solid()

        sunglasses.frame = frame
        frame.left_lens = left_lens
        frame.right_lens = right_lens
        frame.bridge = bridge
        sunglasses.left_temple = left_temple
        sunglasses.right_temple = right_temple

        # Frame constraints
        frame.AddConstraint(left_lens.bb.horizontal_center == -bridge_width / 2)
        frame.AddConstraint(right_lens.bb.horizontal_center == bridge_width / 2)
        frame.AddConstraint(left_lens.bb.vertical_center == 0)
        frame.AddConstraint(right_lens.bb.vertical_center == 0)
        frame.AddConstraint(bridge.bb.horizontal_center == 0)
        frame.AddConstraint(bridge.bb.vertical_center == 0)

        # Temples constraints
        sunglasses.AddConstraint(left_temple.bb.vertical_center == left_lens.bb.vertical_center)
        sunglasses.AddConstraint(right_temple.bb.vertical_center == right_lens.bb.vertical_center)
        sunglasses.AddConstraint(left_temple.bb.left == left_lens.bb.right + frame_thickness)
        sunglasses.AddConstraint(right_temple.bb.right == right_lens.bb.left - frame_thickness)

        return sunglasses

    with AIDL_2D:
        model = sunglasses()
    print(model.Solve())
    model.Render()
    ```

    ### Step 3: Add Geometry

    Let's add the geometric shapes for each structure one at a time.

    1. **Lenses:** Circles
    2. **Frame:** Rectangle around each lens plus the bridge
    3. **Bridge:** Rectangle
    4. **Temples:** Rectangles

    Here's the updated program with geometry:

    ```python
    from AIDL import *

    def sunglasses(
        lens_radius: float = 1 * inch,
        frame_thickness: float = 0.1 * inch,
        bridge_width: float = 0.5 * inch,
        temple_length: float = 4 * inch,
        temple_width: float = 0.25 * inch
    ):
        sunglasses = Assembly()
        frame = Solid()
        left_lens = Solid()
        right_lens = Solid()
        left_temple = Solid()
        right_temple = Solid()
        bridge = Solid()

        sunglasses.frame = frame
        frame.left_lens = left_lens
        frame.right_lens = right_lens
        frame.bridge = bridge
        sunglasses.left_temple = left_temple
        sunglasses.right_temple = right_temple

        # Frame constraints
        frame.AddConstraint(left_lens.bb.horizontal_center == -bridge_width / 2)
        frame.AddConstraint(right_lens.bb.horizontal_center == bridge_width / 2)
        frame.AddConstraint(left_lens.bb.vertical_center == 0)
        frame.AddConstraint(right_lens.bb.vertical_center == 0)
        frame.AddConstraint(bridge.bb.horizontal_center == 0)
        frame.AddConstraint(bridge.bb.vertical_center == 0)

        # Temples constraints
        sunglasses.AddConstraint(left_temple.bb.vertical_center == left_lens.bb.vertical_center)
        sunglasses.AddConstraint(right_temple.bb.vertical_center == right_lens.bb.vertical_center)
        sunglasses.AddConstraint(left_temple.bb.left == left_lens.bb.right + frame_thickness)
        sunglasses.AddConstraint(right_temple.bb.right == right_lens.bb.left - frame_thickness)

        # Geometry
        left_lens.geometry = Circle((0,0), lens_radius)
        right_lens.geometry = Circle((0,0), lens_radius)
        bridge.geometry = Rectangle((0,0), bridge_width, frame_thickness)

        left_temple.geometry = Rectangle((0,0), temple_length, temple_width)
        right_temple.geometry = Rectangle((0,0), temple_length, temple_width)

        # Frame geometry
        left_lens_frame = RoundedRectangle((0,0), 2 * lens_radius + frame_thickness, 2 * lens_radius + frame_thickness, frame_thickness / 2)
        right_lens_frame = RoundedRectangle((0,0), 2 * lens_radius + frame_thickness, 2 * lens_radius + frame_thickness, frame_thickness / 2)
        frame.left_frame = left_lens_frame
        frame.right_frame = right_lens_frame

        frame.AddConstraint(Coincident(left_lens.geometry.center, left_lens_frame.center))
        frame.AddConstraint(Coincident(right_lens.geometry.center, right_lens_frame.center))

        return sunglasses

    with AIDL_2D:
        model = sunglasses()
    print(model.Solve())
    model.Render()
    ```

    This should define the basic layout of the sunglasses with appropriate constraints and geometry. Please let me know if you need any adjustments or additional features for this model.