<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[V2 Feedback : converting V1 examples]]></title><description><![CDATA[<p dir="auto">Hello, I'm slowly converting V1 examples to V2 syntax.<br />
It went ok for the first example, logo :<br />
<img src="/assets/uploads/files/1598705672616-capture-d-%C3%A9cran-de-2020-08-29-14-42-25.png" alt="Capture d’écran de 2020-08-29 14-42-25.png" class=" img-responsive img-markdown" /></p>
<pre><code>// title      : OpenJSCAD.org Logo
// author     : Rene K. Mueller
// license    : MIT License
// revision   : 0.003
// tags       : Logo,Intersection,Sphere,Cube
// file       : logo.jscad

const jscad = require('@jscad/modeling')
const { primitives, transforms, booleans } = jscad
const { cube, sphere } = primitives
const { intersect, subtract, union } = booleans
const { scale, translate } = transforms

function main () {
  return translate([0, 0, 1.5], 
		scale([10, 10, 10], 
			union(
				subtract( 
					cube({size: 3}),
					sphere({radius: 2})
				),
				intersect(
					sphere({radius: 1.3}),
					cube({size: 2.1})
				)
			)
		)
	);
}

module.exports = { main }
</code></pre>
]]></description><link>https://openjscad.nodebb.com/topic/148/v2-feedback-converting-v1-examples</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Mar 2026 15:32:03 GMT</lastBuildDate><atom:link href="https://openjscad.nodebb.com/topic/148.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 29 Aug 2020 12:55:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to V2 Feedback : converting V1 examples on Sun, 30 Aug 2020 14:21:02 GMT]]></title><description><![CDATA[<p dir="auto">Eighth example, lookup :<br />
<img src="/assets/uploads/files/1598797062213-capture-d-%C3%A9cran-de-2020-08-30-16-16-04.png" alt="Capture d’écran de 2020-08-30 16-16-04.png" class=" img-responsive img-markdown" /><br />
It looks ok, but my lookup function is maybe buggy, I needed to stretch return value (x2) to have same lengths as V1, and to add a center to each cylinders to make it look the same.</p>
<pre><code>// title      : Lookup
// author     : OpenSCAD.org, adapted by Rene K. Mueller
// description: testing lookup() function
// file       : lookup.jscad

// from http://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Functions

const jscad = require('@jscad/modeling')
const { primitives, transforms, colors, maths } = jscad
const { cylinder } = primitives
const { translate } = transforms
const { colorize, hslToRgb } = colors
const { vec2 } = maths
const { lerp } = vec2

function getCylinderH (p) {
  return lookup(p, 
		[ [ -200, 5 ], [ -50, 20 ], [ -20, 18 ], [ +80, 25 ], [ +150, 2 ] ]);
}

function main () {
  var w = [];
  for (var i = -100; i &lt;= 100; i += 5) {
    w.push(colorize(hslToRgb([((i + 100) / 200) * 0.3 + 0.6, 1, 0.5]), 
      translate([i, 0, -30],
        cylinder({radius: 4, 
				  height: getCylinderH(i) * 3 *2, segments: 16
				  , center : [i,0,getCylinderH(i) * 3]
				  }))));
  }
  return w;
}

function lookup(ix, L){ // L = [ [ i0, v0], ..., [iN, vN] ]
	if (ix &lt;= L[0][0])
		return L[0][0];
		
	var i = L.length-1;
	if (ix &gt;= L[i][0])
		return L[i][0];
		
	i = L.findIndex( x =&gt; x[0] &gt;= ix);
	v1 = L[i-1][1];
	v2 = L[i][1];
	
	if (ix === L[i-1][0])
		return v1;
		
	if (ix === L[i][0])
		return v2;
	
	var i1 = L[i-1][0], i2 = L[i][0];
	var r = v1 + (v2-v1) / (i2-i1) * (ix-i1);
	
	return r;
}

module.exports = { main }

</code></pre>
]]></description><link>https://openjscad.nodebb.com/post/327</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/327</guid><dc:creator><![CDATA[gilboonet]]></dc:creator><pubDate>Sun, 30 Aug 2020 14:21:02 GMT</pubDate></item><item><title><![CDATA[Reply to V2 Feedback : converting V1 examples on Sun, 30 Aug 2020 12:48:57 GMT]]></title><description><![CDATA[<p dir="auto">Seventh example, expand :<br />
<img src="/assets/uploads/files/1598791713591-capture-d-%C3%A9cran-de-2020-08-30-14-47-35.png" alt="Capture d’écran de 2020-08-30 14-47-35.png" class=" img-responsive img-markdown" /><br />
It looks ok.</p>
<pre><code>// title      : Expand
// author     : OpenSCAD.org, adapted by Rene K. Mueller
// license    : MIT License
// description: testing expand() function
// file       : expand.jscad

const jscad = require('@jscad/modeling')
const { primitives, transforms, booleans, expansions } = jscad
const { cube, cylinder } = primitives
const { subtract, union } = booleans
const { rotate, scale, translate } = transforms
const { expand } = expansions

function main () {
  return scale([10, 10, 10], union(
    expand({delta:0.2, segments:8}, subtract(
			cube({size:2}),
			translate([0.3, -0.3, 0.3], cube({size:2})))),

    translate([-4, 0, 0], subtract(
      cube({size:2}), 
      translate([0.3, -0.3, 0.3], cube({size:2})))),


    expand({delta:0.3, segments:8}, 
      translate([0, -3, 0], cube({size:2}))),

    translate([-4, -3, 0], cube({size:2})),

    expand({delta:0.3, segments:4}, 
			translate([0, 4, 0], 
				cylinder({radius: 1, height: 2, segments: 16}))),

    translate([-4, 4, 0], cylinder({radius: 1, height: 2}))
  ));
}

module.exports = { main }

</code></pre>
]]></description><link>https://openjscad.nodebb.com/post/326</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/326</guid><dc:creator><![CDATA[gilboonet]]></dc:creator><pubDate>Sun, 30 Aug 2020 12:48:57 GMT</pubDate></item><item><title><![CDATA[Reply to V2 Feedback : converting V1 examples on Sun, 30 Aug 2020 11:38:15 GMT]]></title><description><![CDATA[<p dir="auto">Sixth example, transformations :<br />
<img src="/assets/uploads/files/1598775799762-capture-d-%C3%A9cran-de-2020-08-30-10-22-07.png" alt="Capture d’écran de 2020-08-30 10-22-07.png" class=" img-responsive img-markdown" /><br />
It looks ok, except for transform (so, I removed it) that does not seem to work with same parameters as V1.</p>
<pre><code>// title      : transformations
// author     : Mark Moissette
// license    : MIT License
// description: all the different transforms operations

const jscad = require('@jscad/modeling')
const { primitives, transforms } = jscad
const { cube } = primitives
const { scale, translate, rotate, transform } = transforms

function main () {
  const testCube = cube();

  return [
    translate([0, 10, 0], testCube), // simple translation
    translate([10, 0, 0], rotate([10, 5, 0], testCube)), // translate + rotate
    translate([-10, 0, 0], scale([0.5, 0.5, 5], testCube)), // translate + scale
    /*transform([ // matrix transform
      Math.cos(15), -Math.sin(15), 0, 0,
      Math.sin(15), Math.cos(15), 0, 0,
      0, 0, 1, 1,
      0, 0, 0, 1
    ], testCube)*/
  ]
}
module.exports = { main }
</code></pre>
]]></description><link>https://openjscad.nodebb.com/post/325</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/325</guid><dc:creator><![CDATA[gilboonet]]></dc:creator><pubDate>Sun, 30 Aug 2020 11:38:15 GMT</pubDate></item><item><title><![CDATA[Reply to V2 Feedback : converting V1 examples on Sat, 29 Aug 2020 14:17:24 GMT]]></title><description><![CDATA[<p dir="auto">Fifth example, pavillon :<br />
<img src="/assets/uploads/files/1598710541533-capture-d-%C3%A9cran-de-2020-08-29-16-14-28.png" alt="Capture d’écran de 2020-08-29 16-14-28.png" class=" img-responsive img-markdown" /><br />
I needed to move cylinders (columns) and cube (enter) to make them cope with their v1 conterparts</p>
<pre><code>// title      : Example 005
// author     : OpenSCAD.org, adapted by Rene K. Mueller
// license    : MIT License
// description: example005.scad ported to OpenJSCAD
// file       : example005.jscad


const jscad = require('@jscad/modeling')
const { primitives, transforms, booleans } = jscad
const { cube, cylinder, cylinderElliptic } = primitives
const { subtract, union } = booleans
const { translate, scale } = transforms

function example005 () {
  var cy = [];
  for (var i = 0; i &lt;= 5; i++) {
    cy[i] = translate([Math.sin(360 * i / 6) * 80, Math.cos(360 * i / 6) * 80, 80],
							cylinder({height: 200, radius: 10}));
  }
  return translate([0, 0, -120],
    union(
      subtract(
        cylinder({height: 50, radius: 100}),
        translate([0, 0, 10], cylinder({height: 50, radius: 80})),
        translate([100, 0, 35-25], cube({size: 50}))
      ),
      cy,
      translate([0, 0, 200], 
        cylinderElliptic({height: 80, startRadius: [120,120], endRadius: [1,1]}))
    )
  );
}

function main () {
  return scale([1 / 3, 1 / 3, 1 / 3], example005());
}

module.exports = { main }

</code></pre>
]]></description><link>https://openjscad.nodebb.com/post/324</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/324</guid><dc:creator><![CDATA[gilboonet]]></dc:creator><pubDate>Sat, 29 Aug 2020 14:17:24 GMT</pubDate></item><item><title><![CDATA[Reply to V2 Feedback : converting V1 examples on Sat, 29 Aug 2020 13:55:14 GMT]]></title><description><![CDATA[<p dir="auto">Fourth example, box with cutouts :<br />
<img src="/assets/uploads/files/1598709305010-capture-d-%C3%A9cran-de-2020-08-29-15-53-38.png" alt="Capture d’écran de 2020-08-29 15-53-38.png" class=" img-responsive img-markdown" /></p>
<pre><code>// title      : Example 003
// author     : OpenSCAD.org, adapted by Rene K. Mueller
// license    : MIT License
// description: example003.scad ported to OpenJSCAD.org
// file       : example003.jscad


const jscad = require('@jscad/modeling')
const { primitives, transforms, booleans } = jscad
const { cube, cuboid } = primitives
const { subtract, union } = booleans

function example003 () {
  return subtract(
    union(
      cube({size: 30}),
      cuboid({size: [40, 15, 15]}),
      cuboid({size: [15, 40, 15]}),
      cuboid({size: [15, 15, 40]})
    ),
    union(
      cuboid({size: [50, 10, 10]}),
      cuboid({size: [10, 50, 10]}),
      cuboid({size: [10, 10, 50]})
    )
  );
}

function main () {
  return example003();
}

module.exports = { main }
</code></pre>
]]></description><link>https://openjscad.nodebb.com/post/323</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/323</guid><dc:creator><![CDATA[gilboonet]]></dc:creator><pubDate>Sat, 29 Aug 2020 13:55:14 GMT</pubDate></item><item><title><![CDATA[Reply to V2 Feedback : converting V1 examples on Sat, 29 Aug 2020 13:43:06 GMT]]></title><description><![CDATA[<p dir="auto">Third example, cone with cutouts, looks ok :<br />
<img src="/assets/uploads/files/1598708575989-capture-d-%C3%A9cran-de-2020-08-29-15-38-54.png" alt="Capture d’écran de 2020-08-29 15-38-54.png" class=" img-responsive img-markdown" /></p>
<pre><code>// title      : Example 002
// author     : OpenSCAD.org, adapted by Rene K. Mueller
// license    : MIT License
// description: example002.scad ported to OpenJSCAD.org
// file       : example002.jscad

const jscad = require('@jscad/modeling')
const { primitives, transforms, booleans } = jscad
const { cube, cuboid, cylinderElliptic } = primitives
const { intersect, subtract, union } = booleans
const { translate } = transforms

function example002 () {
  return intersect(
    subtract(
      union(
        cube({size: 30}),
        translate([0, 0, -25], cuboid({size: [15, 15, 50]}))
      ),
      union(
        cuboid({size: [50, 10, 10]}),
        cuboid({size: [10, 50, 10]}),
        cuboid({size: [10, 10, 50]})
      )
    ),
    translate([0, 0, 5], 
			cylinderElliptic({height: 50, startRadius: [20,20], endRadius: [5,5]})
    ));
}

function main () {
  return example002();
}

module.exports = { main }
</code></pre>
]]></description><link>https://openjscad.nodebb.com/post/322</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/322</guid><dc:creator><![CDATA[gilboonet]]></dc:creator><pubDate>Sat, 29 Aug 2020 13:43:06 GMT</pubDate></item><item><title><![CDATA[Reply to V2 Feedback : converting V1 examples on Sat, 29 Aug 2020 12:57:52 GMT]]></title><description><![CDATA[<p dir="auto">But the second example, sphere with cutouts doesn't look the same as on V1:<br />
<img src="/assets/uploads/files/1598705820443-capture-d-%C3%A9cran-de-2020-08-29-14-51-45.png" alt="Capture d’écran de 2020-08-29 14-51-45.png" class=" img-responsive img-markdown" /><br />
It may be default centering that is different</p>
<pre><code>// title      : Example 001
// author     : OpenSCAD.org, adapted by Rene K. Mueller
// license    : MIT License
// description: example001.scad ported to OpenJSCAD.org
// file       : example001.jscad

const jscad = require('@jscad/modeling')
const { primitives, transforms, booleans } = jscad
const { cylinder, sphere } = primitives
const { subtract } = booleans
const { rotate } = transforms

function radiusFromDiameter (d) {
 return d / 2;
}

function rotcy (rot, r, h) {
 return rotate(rot, cylinder({radius: r, height: h}));
}

function example001 () {
 var size = 50;
 var hole = 25;
 var radius = radiusFromDiameter(hole);
 var height = radiusFromDiameter(size * 2.5);

 return subtract(
   sphere({radius: radiusFromDiameter(size)}),
   rotcy([0, 0, 0], radius, height),
   rotcy([90, 0, 0], radius, height),
   rotcy([0, 90, 0], radius, height)
 );
}

function main () {
 return example001();
}

module.exports = { main }
</code></pre>
]]></description><link>https://openjscad.nodebb.com/post/320</link><guid isPermaLink="true">https://openjscad.nodebb.com/post/320</guid><dc:creator><![CDATA[gilboonet]]></dc:creator><pubDate>Sat, 29 Aug 2020 12:57:52 GMT</pubDate></item></channel></rss>