Loading
Hey! This thing is still a Work in Progress. Files, instructions, and other stuff might change!

openscad.jscad

by Spiritdude, published

openscad.jscad by Spiritdude Feb 28, 2013

Description

Some wrapper functions to ease the translation from OpenSCAD (.scad) to OpenJsCad (.jscad).

Liked By

view all

License

GNU - GPL
openscad.jscad by Spiritdude is licensed under the GNU - GPL license.

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag. Print Thing Tag

Instructions

LATEST VERSION IS AT github.com/Spiritdude/OpenSCAD.jscad

Example
Go to joostn.github.com/OpenJsCad/processfile.html and paste openscad.jscad in there.

Purpose
OpenJsCad is object oriented, and usually this imposes more verbosity of the source-code, whereas OpenSCAD has a simple syntax many developers are familiar with already, but unfortunately OpenJsCad introduced non-intuitive equivalents (essentially one has to memorize a new set of arguments), therefore a few brief wrapping functions (openscad.jscad) provide a much easier translation of existing .scad to .jscad files:

// example.scad:

union() {
//cube(size=[30,30,0.1],center=true);
translate([3,0,0]) cube();
difference() {
rotate([0,-45,0]) cube(size=[8,7,3],center=true);
sphere(r=3,$fn=20,center=true);
}
translate([10,5,5]) scale([0.5,1,2]) sphere(r=5,$fn=50);
translate([-15,0,0]) cylinder(r1=2,r2=0,h=10,$fn=20);

for(i=[0:19]) {
rotate([0,i/20*360,0]) translate([i,0,0]) rotate([0,i/20*90,i/20*90,0]) cube(size=[1,1.2,.5],center=true);
}
}

the same in .jscad:

function main() {
var cubes = new Array();
for(i=0; i<20; i++) {
cubes[i] = rotate([0,i/20*360,0], translate([i,0,0], rotate([0,i/20*90,i/20*90,0], cube({size:[1,1.2,.5],center:true}))));
}
return union(
//cube({size:[30,30,0.1],center:true}),
translate([3,0,0],cube()),
difference(
rotate([0,-45,0], cube({size:[8,7,3],center:true})),
sphere({r:3,fn:20,center:true})
),
translate([10,5,5], scale([0.5,1,2], sphere({r:5,fn:50}))),
translate([-15,0,0], cylinder({r1:2,r2:0,h:10,fn:20})),
cubes
);
}

Essentially whenever named arguments in .scad appear func(a=1), translate it into func({a:1}), for example:

.scad: translate([0,0,2]) sphere(size=2,$fn=50);
.jscad: translate([0,0,2], sphere({size:2,fn:50}));

Also:
cube(); // 1x1x1
cube(2); // 2x2x2
cube([1,2,3]); // 1x2x3
cube({size: [1,2,3]}); // dito
cube({size:1, center: false});

That's all for now,

Rene K. Mueller
2013/02/28

PS: linear_extrude() and rotate_extrude() equivalents aren't implemented yet.

Comments

You must be logged in to post a comment.

Top