openscad/city skyline/city skyline9


CLIP Score: 25.63

Image

Program

Conversation

city skyline9 image
                scad
// Parameters
number_of_buildings = 10;
min_width = 4;
max_width = 10;
min_height = 20;
max_height = 60;
spacing = 2;

// Seed for random number generation
seed = 1234;

// Function to generate random numbers with a specific seed
function rand(min, max, seed) = fmod((16807 * seed) + 0, 2147483647) / 2147483647 * (max - min) + min;

// Function to generate random widths and heights
function building_parameters(index, min_val, max_val, seed) = 
    [round(rand(min_val, max_val, seed + index * 2)), round(rand(min_val, max_val, seed + index * 2 + 1))];

module city_skyline() {
    x_pos = 0;
    for (i = [0:number_of_buildings-1]) {
        params = building_parameters(i, min_width, max_width, seed);
        width = params[0];
        height = building_parameters(i, min_height, max_height, seed+number_of_buildings)[1];
        
        translate([x_pos, 0, 0])
            square([width, height], center=false);
        
        x_pos = x_pos + width + spacing;
    }
}

city_skyline();

                
                Please generate a 2D CAD file in OpenSCAD for city skyline

Creating a city skyline in OpenSCAD involves defining a series of rectangular prisms (buildings) of various heights and widths. Below is an example of an OpenSCAD script that generates a simple 2D city skyline:

```scad
// Parameters
number_of_buildings = 10;
min_width = 4;
max_width = 10;
min_height = 20;
max_height = 60;
spacing = 2;

// Seed for random number generation
seed = 1234;

// Function to generate random numbers with a specific seed
function rand(min, max, seed) = fmod((16807 * seed) + 0, 2147483647) / 2147483647 * (max - min) + min;

// Function to generate random widths and heights
function building_parameters(index, min_val, max_val, seed) = 
    [round(rand(min_val, max_val, seed + index * 2)), round(rand(min_val, max_val, seed + index * 2 + 1))];

module city_skyline() {
    x_pos = 0;
    for (i = [0:number_of_buildings-1]) {
        params = building_parameters(i, min_width, max_width, seed);
        width = params[0];
        height = building_parameters(i, min_height, max_height, seed+number_of_buildings)[1];
        
        translate([x_pos, 0, 0])
            square([width, height], center=false);
        
        x_pos = x_pos + width + spacing;
    }
}

city_skyline();
```

To use this script, follow these steps:

1. Copy the code into a new OpenSCAD file.
2. Save the file with an appropriate name, for example: `city_skyline.scad`.
3. Open the file in OpenSCAD.
4. Render the scene using F5 to preview or F6 to compile and render.
5. Optionally, export the 2D design to a DXF or other format using `File` -> `Export` -> `Export as DXF`.

This script defines a function to generate a city skyline with randomized building widths and heights. You can adjust parameters like `number_of_buildings`, `min_width`, `max_width`, `min_height`, `max_height`, and `spacing` to customize the appearance of your skyline. The `seed` parameter ensures that the random generation is repeatable; changing this will produce different skylines.