Help with a pretty basic mapping layout of a hollow rectangle

I’ve been trying to write what I assume is a pretty basic mapping to have a hollow rectangle where every LED is somewhere along one of the edges (although I’d like to skip the actual corners I think?). I want to be able to specify the index where each side begins, which I guess would just be 3 variables, since side 1 can be assumed to begin at 0. I don’t want it to just have a width and height variable because the sides don’t quite have an even number of LEDs.

Unfortunately the mapper gives less informational error messages and I usually get to a point where my code can’t be saved because it has an error, but I can’t figure out where the error is. So I don’t even have the code from my latest attempt.

So 4 edges, maybe with corners maybe not?

The mapper is very forgiving about the ranges, so if you pick the first corner as zero,zero, and then you go X pixels, it’ll be (corner is 0,0 if you have a corner), 1,0 2,0 etc, thru to X,0 (could be X-1 if no corner pixel), then you increase the Y, leaving the X at the max, ending at X,Y, then you go back reducing X back to 0, and finally you reduce Y till you are back at 0,0… If you don’t have equal numbers of pixels, it’s a bit harder: are the pixels equally spaced, or not?

Make sense?

You also might want to just take a photo and use the Photo mapper

Structurally, I’m pretty sure I understand how to do it, it’s just that my javascript on the mapper always ends up with some error I can’t find. I’ll give it another shot later and actually save the code somewhere before closing the browser interface.

The spacing is even, and the physical lengths are the same, but the size isn’t a perfect multiple of the LED spacing so I end up with 1 more or less on some sides, where a few mm is the difference between an LED being on one side or another as it wraps around a corner. The LEDs are on the inside of a rectangle, facing in towards the center. It’s probably not worth the effort to avoid using corners since there are like 400 LEDs and even though technically none of the LEDs are actually in the corner, I don’t think it I think the spacing difference is too minor to matter.

1 Like

Save and paste the code here.

Have a poke around with this. It divides the line between two points by the number of pixels along it, excluding the start and end point. My application had an equal number of pixels per side but you can replace the N value under ‘var map’ to whatever you want, they don’t have to be the same.


// Polymapper V1.0

function (pixelCount) {
  
  var N = 10

  function line(Ax, Ay, Az, Bx, By, Bz, N) {
    
    var dx = (Bx - Ax) / N;
    var dy = (By - Ay) / N;
    var dz = (Bz - Az) / N;
    
    var line = [];
    for (var i = 1; i < N; i++) {
      line.push([Ax + i*dx, Ay + i*dy, Az + i*dz]);
    }
    return line;
  }
  
  var map = [];
  
  map = map.concat(line(0, 0, 0, 0, 1, 0, N))
  map = map.concat(line(0, 1, 0, 1, 1, 0, N))
  map = map.concat(line(1, 1, 0, 1, 0, 0, N))
  map = map.concat(line(1, 0, 0, 1, 0, 1, N))
  map = map.concat(line(1, 0, 1, 1, 1, 1, N))
  map = map.concat(line(1, 1, 1, 0, 1, 1, N))
  map = map.concat(line(0, 1, 1, 0, 0, 1, N))
  map = map.concat(line(0, 0, 1, 0, 0, 0, N))
  
  return map;
}

3 Likes

Oh, wow, thank you, this is incredibly flexible and useful. So much better than what I would have come up with and especially easy to see how to use it. I spent the night re-wiring my project so the lights went the other direction instead of trying to write a map so I can actually work on a pattern tomorrow with this!