 |
CLIP Score: 30.37
scad
// Define colors
colors = ["red", "green", "blue", "yellow", "orange", "purple", "cyan", "magenta"];
// Function to generate a stained glass pane
module stainedGlassPane(x, y, width, height, colorIndex) {
color(colors[colorIndex % len(colors)])
square([width, height], center = true)
translate([x, y]);
}
// Main frame
module stainedGlassWindow() {
// Frame dimensions
frameWidth = 200;
frameHeight = 300;
paneWidth = frameWidth / 4;
paneHeight = frameHeight / 6;
// Outer frame (a border)
color("black")
square([frameWidth + 10, frameHeight + 10], center = true);
// Stained glass panes in a grid
for (i = [0:3], j = [0:5]) {
stainedGlassPane(
x = (i - 1.5) * paneWidth,
y = (2.5 - j) * paneHeight,
width = paneWidth - 5,
height = paneHeight - 5,
colorIndex = i + j * 4);
}
}
// Render the stained glass window
stainedGlassWindow();
|
Please generate a 2D CAD file in OpenSCAD for stained glass window
Creating a stained glass window design in OpenSCAD involves defining shapes and applying colors. Here's a basic example of a 2D stained glass window with simple geometric patterns.
```scad
// Define colors
colors = ["red", "green", "blue", "yellow", "orange", "purple", "cyan", "magenta"];
// Function to generate a stained glass pane
module stainedGlassPane(x, y, width, height, colorIndex) {
color(colors[colorIndex % len(colors)])
square([width, height], center = true)
translate([x, y]);
}
// Main frame
module stainedGlassWindow() {
// Frame dimensions
frameWidth = 200;
frameHeight = 300;
paneWidth = frameWidth / 4;
paneHeight = frameHeight / 6;
// Outer frame (a border)
color("black")
square([frameWidth + 10, frameHeight + 10], center = true);
// Stained glass panes in a grid
for (i = [0:3], j = [0:5]) {
stainedGlassPane(
x = (i - 1.5) * paneWidth,
y = (2.5 - j) * paneHeight,
width = paneWidth - 5,
height = paneHeight - 5,
colorIndex = i + j * 4);
}
}
// Render the stained glass window
stainedGlassWindow();
```
### Explanation:
1. **Module for Stained Glass Pane (`stainedGlassPane`)**:
- This module creates a single colored square which will represent a pane of stained glass.
- It uses the `color()` function to apply the color from the `colors` list based on `colorIndex`.
2. **Main Frame Definition (`stainedGlassWindow`)**:
- Sets the dimensions for the entire frame of the window and the individual panes.
- Draws an outer frame (a black border) around the entire window.
3. **Creating the Grid of Panes**:
- A nested for-loop generates the stained glass panes in a grid pattern (4 columns by 6 rows).
- `translate` positions each pane appropriately in the grid.
- Each pane gets a color from the `colors` array using the index calculated as `i + j * 4`.
### How to Use:
- Copy the code into an OpenSCAD editor.
- Adjust the dimensions and `colors` array as needed to fit your specific design preferences.
- Render the design using F5 in OpenSCAD to preview and F6 to compile the preview.
### Additional Customization:
- You can add more panes and shapes by modifying the nested loop structure and geometries.
- To create more intricate designs, you might need to incorporate more advanced shapes like circles or polygons and adjust their positions accordingly.
|