Maximum depth is half of what I thought

I think this might be a dumb mistake which I’ll understand after a good night’s sleep, but maybe someone can help me already.

I have made an easy little app to create gradient images or slopes. Here is the code:

// Define a properties array that returns array of objects representing
// the accepted properties for your application
var properties = [
  {type: 'range', id: "Width", value: 4, min: 1, max: 10, step: 1},
  {type: 'range', id: "Height", value: 4, min: 1, max: 10, step: 1},
  {type: 'range', id: "Depth", value: 0.4, min: 0.0, max: 1.0, step: 0.05},
  {type: 'range', id: "Steps", value: 10, min: 0, max: 100, step: 1},
  {type: 'list', id: "Type", value: "Horizontal", options: ["Horizontal", "Vertical", "Diagonal"]}
];

// Define an executor function that builds an array of volumes,
// and passes it to the provided success callback, or invokes the failure
// callback if unable to do so
var executor = function(args, success, failure) {
  var params = args.params;
  var material = args.material;
  var volumes = [];
  var width = params["Width"];
  var height = params["Height"];
  var depth = params["Depth"];
  var numSteps =  params["Steps"];
  var gradientType = params["Type"];
  
  const changeWidth = (gradientType != "Vertical");
  const changeHeight = (gradientType != "Horizontal");
  const maxDepth = depth*material.dimensions.z;
  const step = 1.0/numSteps;
  for (ratio=1.0; ratio > step; ratio-=step) {
    var w = width * (changeWidth? ratio : 1.0);
    var h = height * (changeHeight? ratio : 1.0);
    var d = depth * ratio;
    volumes.push({
      shape: {
        type: "rectangle",
        center: {
          x: width - (w / 2),
          y: height - (h / 2)
        },
        flipping: {},
        width: w,
        height: h,
        rotation: 0
      },
      cut: {
        depth: d,
        type: 'fill',
        tabPreference: false
      }
    });
  }

  success(volumes);
};

For some reason, when I use the app and set the “Depth” to 0.5, it is already black and if I move the cursor above that, the app gets stuck in “loading”.
So my question is: why is the maximum depth 0.5*material.dimensions.z instead of just material.dimensions.z?

Never mind! I found the bug :frowning:
var d = depth * ratio;
should have been
var d = maxDepth * ratio;

Anyway, anyone interested in this app?
And is there a process to make an app public?

1 Like

I’m not sure exactly what your program does. I get the gradient concept but it isn’t clear from the code how you’re trying to apply the gradient, etc. I’d guess it is making a rectangular slope in either the x or y direction. Are you inserting this into some other XCarve file or running it separately?

It looks like this might be Javascript code which would imply you’re doing this inside a web page. If so, you could upload the html file (or a zip of a folder) and others could download and try it.

@LarryLandry: this is an app which runs inside Easel.
So the output of this is a set of evenly-spaced rectangles into your Easel project. It allows you to carve slopes.

Would be real nice if it can be varied to a v bit angle.

@cd127, I believe you just need to send an email to development@inventables.com with the link to your apps edit page and give them a description of what the app does

1 Like