Skip to content

Instantly share code, notes, and snippets.

@peterwake
Last active April 16, 2020 17:06
Show Gist options
  • Select an option

  • Save peterwake/3c336d829d91ecd3e6dd51fafaa0aee5 to your computer and use it in GitHub Desktop.

Select an option

Save peterwake/3c336d829d91ecd3e6dd51fafaa0aee5 to your computer and use it in GitHub Desktop.

Revisions

  1. Peter Wake revised this gist Apr 16, 2020. 1 changed file with 124 additions and 22 deletions.
    146 changes: 124 additions & 22 deletions tower_bridge.js
    Original file line number Diff line number Diff line change
    @@ -1,29 +1,58 @@
    // openjscad.org
    // Tower Bridge - work in progress
    // Tower Bridge

    let fancy_bricks = true;

    function random_colour() {
    // based on 'BurlyWood';
    return [
    (222 + Math.random() * 10) / 255,
    (184 + Math.random() * 10) / 255,
    (135 + Math.random() * 10) / 255
    ];
    }

    function styled_cube(orientation) {
    let hash = {};

    if (orientation === 0) {
    hash.size = [30, 6, 2];
    hash.center = [15, 3, 1];
    } else {
    hash.size = [30, 2, 6];
    hash.center = [15, 1, 3];
    }
    if (fancy_bricks) {
    hash.radius = 0.25;
    hash.roundradius = 0.2
    }
    return cube(hash);
    }

    function plank(x, y, z, r) {
    return color('burlywood', cube({
    size: [30, 6, 2],
    center: [15, 3, 1]
    })
    .rotateZ(r)
    .translate([x, y, 1 + z * 2])
    return color(random_colour(), styled_cube(0)
    .rotateZ(r)
    .translate([x, y, 1 + z * 2])
    );
    }

    function plank2(x, y, z, r) {
    return color('BlanchedAlmond', cube({
    size: [30, 2, 6],
    center: [15, 1, 3]
    })
    .rotateZ(r)
    .translate([x, y, 1 + z * 2])
    return color(random_colour(), styled_cube(1)
    .rotateZ(r)
    .translate([x, y, 1 + z * 2])
    );
    }

    function plank3(x, y, z, r) {
    return color(random_colour(), styled_cube(0)
    .rotateY(r)
    .translate([x, y, 1 + z * 2])
    );
    }

    function main() {

    var z;
    var x, y, z;

    /* Base */
    var baseArr = [];
    @@ -48,8 +77,8 @@ function main() {
    [-1, 1, 3]
    ];

    bArr.forEach(function (arr, h) {
    arr.forEach(function (x1, _ix) {
    bArr.forEach(function(arr, h) {
    arr.forEach(function(x1, _ix) {
    bridgeArr.push(plank(15 * x1, -12, h + 12, 0));
    bridgeArr.push(plank(15 * x1, 12, h + 12, 0));
    });
    @@ -61,7 +90,7 @@ function main() {

    let footwayArr = [];

    for (var x = -28; x < 60; x += 7) {
    for (x = -28; x < 60; x += 7) {
    footwayArr.push(plank(x, 0, 17, 90));
    }

    @@ -97,15 +126,88 @@ function main() {
    [1, 3]
    ];

    bArr2.forEach(function (arr, h) {
    arr.forEach(function (x1, _ix) {
    bArr2.forEach(function(arr, h) {
    arr.forEach(function(x1, _ix) {
    topBridgeArr.push(plank2(15 * x1, -12, h * 3 + 34, 0));
    topBridgeArr.push(plank2(15 * x1, 12, h * 3 + 34, 0));
    });
    });

    let topBridge = union(topBridgeArr);

    /*let w2 = w1.translate([120, 0, 0]);*/
    return [base, bridge, footway, tower, topBridge];
    /* Footway 2 */

    let footway2Arr = [];

    for (x = -12; x < 65; x += 7) {
    footway2Arr.push(plank(x, 0, 48, 90));
    }

    let footway2 = union(footway2Arr);

    /* Tower 2 */

    let tower2Arr = [];

    for (z = 50; z < 58; z += 6) {
    tower2Arr.push(plank2(0, 14, z, 0));
    tower2Arr.push(plank2(0, -14, z, 0));
    tower2Arr.push(plank2(-14, 0, z + 3, 90));
    tower2Arr.push(plank2(14, 0, z + 3, 90));

    }

    let tower2 = union(tower2Arr);

    /* Roof */

    let roofArr = [];

    roofArr.push(plank2(-1, 0, 59, 90));
    roofArr.push(plank2(1, 0, 59, 90));

    for (x = -15; x <= 15; x += 30) {
    for (y = -12; y <= 12; y += 6) {
    roofArr.push(plank(x, y, 61, 0));
    }
    }

    for (z = 62; z < 72; z++) {
    roofArr.push(plank(0, 0, z, 90));
    }

    roofArr.push(plank(-29, 0, 62, 90));
    roofArr.push(plank(29, 0, 62, 90));
    roofArr.push(plank2(-25, 0, 63, 90));
    roofArr.push(plank2(25, 0, 63, 90));

    for (y = -12; y <= 12; y += 6) {
    roofArr.push(plank3(12.5, y, 67.3, 46.5));
    roofArr.push(plank3(-12.5, y, 67.3, -46.5));
    }

    roofArr.push(plank2(0, 0, 73, 90));

    let roof = union(roofArr);

    /* Make two structures, rotate one of them, slide them to the right place */

    let side1 = union([base, bridge, footway, tower, topBridge, footway2, tower2, roof]);
    let side2 = side1.rotateZ(180);

    side1 = side1.translate([-60, 0, 0]);
    side2 = side2.translate([60, 0, 0]);

    /* Connectors */

    let connectorArr = [];

    connectorArr.push(plank2(0, -12, 43, 0));
    connectorArr.push(plank2(0, 12, 43, 0));

    connectorArr.push(plank(0, -12, 15, 0));
    connectorArr.push(plank(0, 12, 15, 0));
    let connectors = union(connectorArr);

    return [side1, side2, connectors];
    }
  2. Peter Wake created this gist Apr 15, 2020.
    111 changes: 111 additions & 0 deletions tower_bridge.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,111 @@
    // openjscad.org
    // Tower Bridge - work in progress

    function plank(x, y, z, r) {
    return color('burlywood', cube({
    size: [30, 6, 2],
    center: [15, 3, 1]
    })
    .rotateZ(r)
    .translate([x, y, 1 + z * 2])
    );
    }

    function plank2(x, y, z, r) {
    return color('BlanchedAlmond', cube({
    size: [30, 2, 6],
    center: [15, 1, 3]
    })
    .rotateZ(r)
    .translate([x, y, 1 + z * 2])
    );
    }

    function main() {

    var z;

    /* Base */
    var baseArr = [];
    for (z = 0; z < 12; z += 2) {
    baseArr.push(plank(-12, 0, z, 90));
    baseArr.push(plank(12, 0, z, 90));
    baseArr.push(plank(0, -12, z + 1, 0));
    baseArr.push(plank(0, 12, z + 1, 0));
    }

    let base = union(baseArr);

    /* Bridge */

    let bridgeArr = [];

    let bArr = [
    [-1, 1],
    [0, 2],
    [-1, 1, 3],
    [0, 2],
    [-1, 1, 3]
    ];

    bArr.forEach(function (arr, h) {
    arr.forEach(function (x1, _ix) {
    bridgeArr.push(plank(15 * x1, -12, h + 12, 0));
    bridgeArr.push(plank(15 * x1, 12, h + 12, 0));
    });
    });

    let bridge = union(bridgeArr);

    /* Footway */

    let footwayArr = [];

    for (var x = -28; x < 60; x += 7) {
    footwayArr.push(plank(x, 0, 17, 90));
    }

    let footway = union(footwayArr);

    /* Tower */

    let towerArr = [];

    towerArr.push(plank2(0, 14, 19, 0));
    towerArr.push(plank2(0, -14, 19, 0));
    towerArr.push(plank2(0, -14, 22, 0));
    towerArr.push(plank2(0, 14, 22, 0));

    for (z = 25; z < 48; z += 6) {
    towerArr.push(plank2(-14, 0, z, 90));
    towerArr.push(plank2(14, 0, z, 90));
    towerArr.push(plank2(0, 14, z + 3, 0));
    towerArr.push(plank2(0, -14, z + 3, 0))
    }

    let tower = union(towerArr);

    /* Top Bridge */

    let topBridgeArr = [];

    let bArr2 = [
    [1],
    [2],
    [1, 3],
    [2],
    [1, 3]
    ];

    bArr2.forEach(function (arr, h) {
    arr.forEach(function (x1, _ix) {
    topBridgeArr.push(plank2(15 * x1, -12, h * 3 + 34, 0));
    topBridgeArr.push(plank2(15 * x1, 12, h * 3 + 34, 0));
    });
    });

    let topBridge = union(topBridgeArr);

    /*let w2 = w1.translate([120, 0, 0]);*/
    return [base, bridge, footway, tower, topBridge];
    }