js2scad provides a library and a CLI tool for converting JavaScript code into OpenSCAD input format. This tool is for those, who like JavaScript and want to create OpenSCAD 3D models using this language.
Suppose we want to draw a couple of tyres:
function createTyre(diskDiameter, width, profilePerCent) {
var profile = width * profilePerCent / 100.00;
var radius = diskDiameter * 25.4 / 2.0 + profile;
return scad.Difference(
scad.Cylinder(width, {r: radius, center: true}),
scad.Cylinder(width + 2, {r: radius - profile, center: true})
);
}
var sportTyre = createTyre(18, 220, 50);
sportTyre.rotate([90, 0, 0]).translate([0, 250, 0]);
var cityTyre = createTyre(13, 155, 65);
cityTyre.rotate([90, 0, 0]);
Then, translate JS code into OpenSCAD format and open result in OpenSCAD:
$ js2scad -i tyre.js -o tyre.scad
$ openscad tyre.scad
Press F5 in OpenSCAD GUI and you will get something like this: