You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.2 KiB

  1. function updateDimensions( dimension ){
  2. less.modifyVars({"@sizeWidth":dimension+"px"});
  3. }
  4. function populateHoneycomb( ){
  5. honeyCells = jsonExample;
  6. var height = "innerHeight" in window
  7. ? window.innerHeight
  8. : document.documentElement.offsetHeight;
  9. var width = "innerWidth" in window
  10. ? window.innerWidth
  11. : document.documentElement.offsetWidth;
  12. var cellWidth = width/(honeyCells.width+0.7);
  13. updateDimensions( cellWidth );
  14. var honeyComb = document.getElementById("honeyComb");
  15. for (var i = honeyCells.height - 1; i >= 0; i--) {
  16. var even = (i%2 == 0) ? "even" : "";
  17. var container = document.createElement('div');
  18. container.className = "hex-row " + even;
  19. honeyComb.appendChild(container);
  20. for (var j = honeyCells.width - 1; j >= 0; j--) {
  21. var hexCell = document.createElement("div");
  22. hexCell.className = "hex";
  23. container.appendChild(hexCell);
  24. var topPart = document.createElement('div');
  25. topPart.className = "top";
  26. var middlePart = document.createElement('div');
  27. middlePart.className = "middle";
  28. var bottomPart = document.createElement('div');
  29. bottomPart.className = "bottom";
  30. hexCell.appendChild(topPart);
  31. hexCell.appendChild(middlePart);
  32. hexCell.appendChild(bottomPart);
  33. };
  34. };
  35. }
  36. function setFilled(){
  37. honeyCells = jsonExample;
  38. var hexCells = document.getElementsByClassName("hex");
  39. for (var i = honeyCells.filled.length - 1; i >= 0; i--) {
  40. honeyCell = hexCells[ (honeyCells.filled[i].x * honeyCells.width)+honeyCells.filled[i].y];
  41. honeyCell.className += " disabled";
  42. };
  43. }
  44. jsonExample = {"height":15,"width":15,"sourceSeeds":[0],"units":[{"members":[{"x":0,"y":0}],"pivot":{"x":0,"y":0}}],"id":1,"filled":[{"x":2,"y":4},{"x":3,"y":4},{"x":4,"y":4},{"x":5,"y":4},{"x":6,"y":4},{"x":11,"y":4},{"x":2,"y":5},{"x":8,"y":5},{"x":11,"y":5},{"x":2,"y":6},{"x":11,"y":6},{"x":2,"y":7},{"x":3,"y":7},{"x":4,"y":7},{"x":8,"y":7},{"x":11,"y":7},{"x":2,"y":8},{"x":9,"y":8},{"x":11,"y":8},{"x":2,"y":9},{"x":8,"y":9},{"x":2,"y":10},{"x":3,"y":10},{"x":4,"y":10},{"x":5,"y":10},{"x":6,"y":10},{"x":9,"y":10},{"x":11,"y":10}],"sourceLength":100};