ulfben

One dimensional array as grid

Jan 30th, 2017
146
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //one dimensional array as grid
  2. var grid = [];
  3. var numCols = 5;
  4.  
  5. function get(row, col){
  6.     return grid[row*numCols + col];
  7. }
  8.  
  9. function set(row, col, value){
  10.     return grid[row*numCols + col] = value;
  11. }
  12.  
  13. //one dimensional array as grid with stride
  14. //example;  rgba pixel data
  15. function getPixel(x, y){
  16.     var index = (y*imageData.width + x) * 4; //4 integers for RGBA
  17.     var red = imageData[index];
  18.     var green = imageData[index+1];
  19.     var blue = imageData[index+2];
  20.     var alpha = imageData[index+3];
  21.     var alphaPrcnt = alpha/255; //0-1  
  22.    
  23.     var rgba = (red << 24) + (green << 16) + (blue << 8) + (alpha);
  24.     return rgba;
  25. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×