Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function draw_mesh(x, y){
- let bitmask = cells[y][x]; // The case bitmask
- // Cell vectors
- let a = createVector(x * REZ, y * REZ);
- let b = createVector(a.x + REZ, a.y);
- let c = createVector(b.x, b.y + REZ);
- let d = createVector(a.x, c.y);
- //Line positions
- let top = p5.Vector.lerp(a, b, 0.5);
- let bottom = p5.Vector.lerp(c, d, 0.5);
- let left = p5.Vector.lerp(a, d, 0.5);
- let right = p5.Vector.lerp(b, c, 0.5);
- push();
- switch(bitmask){
- case 0:
- case 15:
- break;
- case 1:
- case 14:
- vLine(bottom, left);
- break;
- case 2:
- case 13:
- vLine(bottom, right);
- break;
- case 3:
- case 12:
- vLine(left, right);
- break;
- case 4:
- case 11:
- vLine(right, top);
- break;
- case 5: //-------------Special cases ------------
- vLine(left, bottom);
- vLine(top, right);
- case 10:
- vLine(bottom, left);
- vLine(right, top);
- // ---------------------------------------------
- break;
- case 6:
- case 9:
- vLine(top, bottom);
- break;
- case 7:
- case 8:
- vLine(left, top);
- break;
- default:
- throw "Bad bitmask value. BAD.";
- }
- pop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement