Advertisement
ShadowDisruptor

Javascript Diamond Thingy

Mar 23rd, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var positive = true; // Start going down or up
  2. var h = 6; // How wide the diamonds should go to
  3. var contCount = 5; // How many columns of diamonds should there be
  4. var t = h * 2; // Don't edit
  5.  
  6. // Loop and make the pyramids
  7. for (var i = 0; i < (h * 100) * Math.PI; i++) {
  8.     // Decide whether we need to be going up or down
  9.     var output = "";
  10.     if (i % h == 0) {
  11.         positive = !positive;
  12.         continue;
  13.     }
  14.  
  15.     // Draw contCount diamond parts
  16.     for (var cont = 0; cont < contCount; cont++) {
  17.         var c = 0; // How many chars we're at
  18.  
  19.         // --- Left
  20.         // Draw left dashes
  21.         for (var j = 0; j < (positive ? i % h : h - i % h) - 1; j++) {
  22.             output += "-";
  23.             c++;
  24.         }
  25.         // Draw left slashes
  26.         output += (i % h == 0) ? (positive ? "<" : ">") : (positive ? "\\" : "/");
  27.         // Create whitespace to straighten line
  28.         for (; c < h - 1; c++) output += " ";
  29.  
  30.         // --- Right
  31.         // Create whitespace to justify right
  32.         var temp = c + (!positive ? i % h : h - i % h) - 1;
  33.         for (; c < temp; c++) output += " ";
  34.         // Draw right slashes
  35.         output += (i % h == 0) ? (!positive ? "<" : ">") : (!positive ? "\\" : "/");
  36.         // Draw right dashes
  37.         for (var j = 0; j < (positive ? i % h : h - i % h) - 1; j++) {
  38.             output += "-";
  39.             c++;
  40.         }
  41.     }
  42.     // Print output
  43.     console.info(output);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement