Advertisement
Guest User

Untitled

a guest
Aug 13th, 2020
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function draw_mesh(x, y){
  2.     let bitmask = cells[y][x]; // The case bitmask
  3.    
  4.     // Cell vectors
  5.     let a = createVector(x * REZ, y * REZ);
  6.     let b = createVector(a.x + REZ, a.y);
  7.     let c = createVector(b.x, b.y + REZ);
  8.     let d = createVector(a.x, c.y);
  9.    
  10.     //Line positions
  11.     let top = p5.Vector.lerp(a, b, 0.5);
  12.     let bottom = p5.Vector.lerp(c, d, 0.5);
  13.     let left = p5.Vector.lerp(a, d, 0.5);
  14.     let right = p5.Vector.lerp(b, c, 0.5);
  15.    
  16.     push();
  17.     switch(bitmask){
  18.         case 0:
  19.         case 15:
  20.             break;
  21.         case 1:
  22.         case 14:
  23.             vLine(bottom, left);
  24.             break;
  25.         case 2:
  26.         case 13:
  27.             vLine(bottom, right);
  28.             break;
  29.         case 3:
  30.         case 12:
  31.             vLine(left, right);
  32.             break;
  33.         case 4:
  34.         case 11:
  35.             vLine(right, top);
  36.             break;
  37.         case 5:  //-------------Special cases ------------
  38.             vLine(left, bottom);
  39.             vLine(top, right);
  40.         case 10:
  41.             vLine(bottom, left);
  42.             vLine(right, top);
  43.             // ---------------------------------------------
  44.             break;
  45.         case 6:
  46.         case 9:
  47.             vLine(top, bottom);
  48.             break;
  49.         case 7:
  50.         case 8:
  51.             vLine(left, top);
  52.             break;
  53.         default:
  54.             throw "Bad bitmask value.  BAD.";      
  55.     }
  56.     pop();
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement