Last active
August 29, 2015 14:05
-
-
Save tmpvar/813f032db383fcb845f0 to your computer and use it in GitHub Desktop.
livecad snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var buttons = []; | |
var rows = 1; | |
var columns = 1; | |
var distanceBetween = 20; | |
var borderH = 1; | |
var borderW = 2; | |
var w = rows*distanceBetween + borderW | |
var h = columns*distanceBetween + borderH | |
var materialWidth = 1/8 * 25.4; // 1/8" in mm | |
var material = box(w, materialWidth, h) | |
.translate(w/2, 6 - materialWidth/2, h/2); | |
var mySwitch = makeSwitch(0, 0) | |
.translate(distanceBetween/2, 0, distanceBetween/2); | |
for (var r = 0; r<rows; r++) { | |
for (var c = 0; c<columns; c++) { | |
material = material.cut(mySwitch.translate( | |
r * distanceBetween + borderW/2, 0, c * distanceBetween + borderH/2 | |
)) | |
} | |
} | |
display(material); | |
function makeSwitch(x, z) { | |
// bottom of the shape | |
var shape = box(14, 5, 14).translate(x, 2.5, z); | |
// midway flange | |
shape = shape.union(box(15.6, 1, 15.6).translate(x, .5 + 5, z)); | |
// top | |
shape = shape.union(box(14, 5, 14).translate(x, 7.5+1, z)) | |
// bottom cylinder | |
shape = shape.union(cylinder(3.3, 3.3).translate(x, -3.3/2, z)) | |
// key adapter | |
shape = shape.union(cylinder(2, 3.6).translate(x, 11 + 1.8, z)) | |
shape = shape.cut( | |
box(1.25, 3.6, 1.25).translate(x + 1.25, 11 + 1.8, z + 1.25) | |
) | |
shape = shape.cut( | |
box(1.25, 3.6, 1.25).translate(x -1.25, 11 + 1.8, z + 1.25) | |
) | |
shape = shape.cut( | |
box(1.25, 3.6, 1.25).translate(x -1.25, 11 + 1.8, z -1.25) | |
) | |
shape = shape.cut( | |
box(1.25, 3.6, 1.25).translate(x + 1.25, 11 + 1.8, z -1.25) | |
) | |
return shape; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cubes = []; | |
for (var i=1; i<20; i++) { | |
cubes.push( | |
cube(i*20).translate(i*i*12, Math.sin(i)*100, 0) | |
); | |
} | |
display(cubes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('hyperquest') | |
var baseUrl = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/' | |
var url = baseUrl + 'all_day.geojson' | |
request.get(url, function(e, r) { | |
r.on('data', function(d) { | |
var o = JSON.parse(d); | |
var spheres = []; | |
var magnifier = 1.0; | |
o.features.forEach(function(feature) { | |
if (!feature.properties.mag) { return; } | |
var coords = feature.geometry.coordinates; | |
spheres.push( | |
cube(feature.properties.mag * magnifier) | |
.translate(coords[0], coords[1], coords[2]) | |
); | |
}); | |
display(spheres); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Nema 17 Stepper Motor Mount | |
var distanceBetweenHoles = 31; | |
var centerCircleDiameter = 22; | |
var dimension = 42; // width and height | |
var materialWidth = 3; | |
// compute hole pattern | |
var triLeg = distanceBetweenHoles/2; | |
var l = Math.sqrt(triLeg*triLeg*2); | |
var b = box(dimension, materialWidth, dimension); | |
b = b.cut(cylinder(centerCircleDiameter/2, materialWidth)); | |
var TAU = Math.PI*2; | |
var a45 = Math.PI/4; | |
var a90 = Math.PI/2 | |
for (var i=1; i<=4; i++) { | |
var c = cylinder(1.5, materialWidth).translate( | |
l * Math.sin(i * a90 + a45), | |
0, | |
l * Math.cos(i * a90 + a45) | |
); | |
b = b.cut(c) | |
} | |
display(b); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// by @maxharris9 | |
function corners(commonPrimitive, x, z) { | |
return [ | |
commonPrimitive.translate(x, 0, z), | |
commonPrimitive.translate(-x, 0, -z), | |
commonPrimitive.translate(x, 0, -z), | |
commonPrimitive.translate(-x, 0, z) | |
]; | |
} | |
function cutCorners (boxWidth, boxHeight, boxDepth, filletConst) { | |
var x = (boxWidth / 2) - (filletConst / 2); | |
var z = (boxDepth / 2) - (filletConst / 2); | |
var commonBox = box(filletConst, boxHeight, filletConst); | |
return corners(commonBox, x, z); | |
} | |
function makeCyl (boxWidth, boxHeight, boxDepth, filletConst) { | |
var x = (boxWidth / 2) - filletConst; | |
var z = (boxDepth / 2) - filletConst; | |
var commonCyl = cylinder(filletConst, boxHeight); | |
return corners(commonCyl, x, z); | |
} | |
function filletCornerBox(boxWidth, boxHeight, boxDepth, filletRadius) { | |
var someBox = box(boxWidth, boxHeight, boxDepth); | |
var bits = cutCorners(boxWidth, boxHeight, boxDepth, filletRadius); | |
var cyls = makeCyl(boxWidth, boxHeight, boxDepth, filletRadius); | |
for (var i = 0; i < 4; i++) { | |
someBox = someBox.cut(bits[i]); | |
} | |
for (var j = 0; j < 4; j++) { | |
someBox = someBox.union(cyls[j]); | |
} | |
return someBox; | |
} | |
display(filletCornerBox(15, 0.3, 12, 0.5)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var w = 100; | |
var plate = box(w, 2, w); | |
var r = 5 | |
var cuttingTool = cylinder(r, 4).translate(r, 0, 0) | |
cuttingTool = cuttingTool | |
.union(box(r*2, 4, r*2)) | |
.union(cuttingTool.translate(-10, 0, 0)) | |
.translate(w/2-r*2.1, 0, w/2 + r + 1.1) | |
for (var i=0; i<8; i++) { | |
cuttingTool = cuttingTool.translate(0, 0, - (r + r*1.5)); | |
plate = plate.cut(cuttingTool) | |
} | |
display(plate) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var c = cube(10); | |
var pos = 0; | |
setInterval(function() { | |
display(c, c.translate(pos++, 0, 0)) | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment