mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-22 06:13:10 +02:00
refactor
This commit is contained in:
@@ -3,7 +3,7 @@ use <shape_trapezium.scad>;
|
|||||||
use <arc.scad>;
|
use <arc.scad>;
|
||||||
use <shear.scad>;
|
use <shear.scad>;
|
||||||
use <util/rand.scad>;
|
use <util/rand.scad>;
|
||||||
use <experimental/tiles_wang_2e.scad>;
|
use <experimental/tile_w2e.scad>;
|
||||||
|
|
||||||
mask = [
|
mask = [
|
||||||
[0, 1, 1, 0, 0, 0, 1, 1, 0],
|
[0, 1, 1, 0, 0, 0, 1, 1, 0],
|
||||||
@@ -24,7 +24,18 @@ random_city(rows, columns, mask);
|
|||||||
|
|
||||||
module random_city(rows, columns, mask) {
|
module random_city(rows, columns, mask) {
|
||||||
tile_width = 30;
|
tile_width = 30;
|
||||||
tiles_wang_2e(rows, columns, tile_width, mask) {
|
|
||||||
|
module tiles() {
|
||||||
|
for(tile = tile_w2e(rows, columns, mask)) {
|
||||||
|
x = tile[0];
|
||||||
|
y = tile[1];
|
||||||
|
i = tile[2];
|
||||||
|
translate([x, y] * tile_width)
|
||||||
|
children(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tiles() {
|
||||||
tile00();
|
tile00();
|
||||||
tile01();
|
tile01();
|
||||||
tile02();
|
tile02();
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
use <experimental/tiles_wang_2e.scad>;
|
use <experimental/tile_w2e.scad>;
|
||||||
use <box_extrude.scad>;
|
use <box_extrude.scad>;
|
||||||
|
|
||||||
rows = 8;
|
rows = 8;
|
||||||
@@ -13,24 +13,13 @@ module tube_box(rows, columns, tile_width) {
|
|||||||
quarter_w = tile_width / 4;
|
quarter_w = tile_width / 4;
|
||||||
eighth_w = tile_width / 8;
|
eighth_w = tile_width / 8;
|
||||||
|
|
||||||
translate([eighth_w, eighth_w, -eighth_w])
|
translate([eighth_w, eighth_w, -eighth_w] + [tile_width, tile_width] / 2)
|
||||||
tiles_wang_2e(rows, columns, tile_width) {
|
for(tile = tile_w2e(rows, columns)) {
|
||||||
tube_tile(0, tile_width);
|
x = tile[0];
|
||||||
tube_tile(1, tile_width);
|
y = tile[1];
|
||||||
tube_tile(2, tile_width);
|
i = tile[2];
|
||||||
tube_tile(3, tile_width);
|
translate([x, y] * tile_width)
|
||||||
tube_tile(4, tile_width);
|
tube_tile(i, tile_width);
|
||||||
tube_tile(5, tile_width);
|
|
||||||
tube_tile(6, tile_width);
|
|
||||||
tube_tile(7, tile_width);
|
|
||||||
tube_tile(8, tile_width);
|
|
||||||
tube_tile(9, tile_width);
|
|
||||||
tube_tile(10, tile_width);
|
|
||||||
tube_tile(11, tile_width);
|
|
||||||
tube_tile(12, tile_width);
|
|
||||||
tube_tile(13, tile_width);
|
|
||||||
tube_tile(14, tile_width);
|
|
||||||
tube_tile(15, tile_width);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
box_extrude(height = tile_width, shell_thickness = eighth_w)
|
box_extrude(height = tile_width, shell_thickness = eighth_w)
|
||||||
|
@@ -1,49 +0,0 @@
|
|||||||
// wang tiles - 2 edges
|
|
||||||
module tiles_wang_2e(rows, columns, tile_width, mask, seed) {
|
|
||||||
edges = is_undef(seed) ? [
|
|
||||||
for(y = [0:rows])
|
|
||||||
[
|
|
||||||
for(x = [0:columns])
|
|
||||||
let(rs = rands(0, 1, 2))
|
|
||||||
[round(rs[0]), round(rs[1])]
|
|
||||||
]
|
|
||||||
] : [
|
|
||||||
for(y = [0:rows])
|
|
||||||
[
|
|
||||||
for(x = [0:columns])
|
|
||||||
let(rs = rands(0, 1, 2, seed + y * columns + x))
|
|
||||||
[round(rs[0]), round(rs[1])]
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
m = is_undef(mask) ? [
|
|
||||||
for(y = [0:rows - 1])
|
|
||||||
[for(x = [0:columns - 1]) 1]
|
|
||||||
] : [
|
|
||||||
for(y = rows - 1; y > -1; y = y - 1)
|
|
||||||
[for(x = [0:columns - 1]) mask[y][x]]
|
|
||||||
];
|
|
||||||
|
|
||||||
/*
|
|
||||||
1
|
|
||||||
. - .
|
|
||||||
8 | | 2
|
|
||||||
. - .
|
|
||||||
4
|
|
||||||
*/
|
|
||||||
|
|
||||||
half_w = tile_width / 2;
|
|
||||||
translate([half_w, half_w])
|
|
||||||
for(y = [0:rows - 1]) {
|
|
||||||
for(x = [0:columns - 1]) {
|
|
||||||
if(m[y][x] == 1) {
|
|
||||||
i = (edges[y + 1][x][0] == 1 ? 1 : 0) +
|
|
||||||
(edges[y][x + 1][1] == 1 ? 2 : 0) +
|
|
||||||
(edges[y][x][0] == 1 ? 4 : 0) +
|
|
||||||
(edges[y][x][1] == 1 ? 8 : 0);
|
|
||||||
translate([x, y] * tile_width)
|
|
||||||
children(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user