Pigeonhole Principle

by Ryan Allison

HTML

<head>
  <!-- Load plotly.js into the DOM -->
  <script src="https://www.desmos.com/api/v1.6/calculator.js?apiKey=dcb31709b452b1cf9dc26972add0fda6"></script>
  <script src='https://cdn.plot.ly/plotly-2.4.2.min.js'></script>
  <script src="https://code.highcharts.com/highcharts.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
  <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
  <script type="text/javascript" id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
</head>

<body>
  <!-- Title -->

  <h1 id='title'>
    The PigeonHole Principle
  </h1>

  <div id="sliders" class="padded">
    <div> \(P:\)
      <input type="range" min="1" max="2" value="1" step="1" id="pigeons" />
      <div id="outputPVal" style="display: inline-block">1</div>
    </div>
    <div> \(H:\)
      <input type="range" min="1" max="20" value="1" step="1" id="pigeonholes" />
      <div id="outputHVal" style="display: inline-block">1</div>
    </div>
  </div>

  <div id='leftSide' class="leftColumnClass">
    <b>Instructions: Drag the circles (pigeons) into the boxes (pigeonholes).</b>

    <div id='divSample' class="sample" style="padding: 10px">
      <div>
        <b>Pigeonholes:</b> <br>
      </div><br>
      <div id="drop-targets" class="drop-targets">
      </div>

    </div>
    <div class="dropzone"></div>
  </div>


  <div id='rightSide' class="sample" style="margin-left: 51%; padding: 5px">
    Pigeons = <div id="pVal" style="display: inline-block">1</div>
    <div id='pigeonStart'>

    </div>

  </div>
<div class="dropzone" style="margin-left: 51%">
        <div id="draggable" class="circle" draggable="true" ondragstart="event.dataTransfer.setData('text/plain',null)" >
          This div is draggable
        </div>
      </div>


</body>

CSS

body {
  background-color: gainsboro;
  font-family: arial;
}

.centered {
  text-align: center;
}

.padded {
  padding-top: 10px;
  padding-bottom: 10px;
  padding-left: 20px;
  padding-right: 20px;
}

.left {
  text-align: left;
  width: 48%;
  float: left;
}

.leftColumnClass {
  width: 49%;
  float: left;
  text-align: left;
  padding: 5px;
}

.rightColumnClass {
  margin-left: 51%;
  padding: 5px;
}

.sample {
  position: relative;
  text-align: center;
  border-radius: 10px;
  background-color: whitesmoke;
  padding: 12px;
  border: 1px solid black;
}

.reveal {
  border-radius: 10px;
  background-color: whitesmoke;
  padding: 12px;
  border: 1px solid black;
}

.vc {
  text-align: center;
  margin: 0;
  position: absolute;
}

.circle {
  position: absolute;
  background-color: #229954;
  right: 25%;
  top: 25%;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  border: 1px solid;
  display: inline-block;
}

.square {
  display: inline-block;
  text-align: center;
  height: 80px;
  width: 60px;
  border: 1px solid;
}

#draggable {
    width: 200px;
    height: 20px;
    text-align: center;
    background: white;
  }

.drag-over {
    border: dashed 3px red;
}

.dropzone {
    width: 200px;
    height: 20px;
    background: blueviolet;
    margin-bottom: 10px;
    padding: 10px;
  }

table.center {
  margin-left: auto;
  margin-right: auto;
}

JavaScript

var pigeons = 1;
var pigeonholes = 1;
var dragged;


$("#pigeons").on("change", function() {
  pigeons = parseFloat($(this).val());
  $('#outputPVal').html(pigeons);
  $('#pVal').html(pigeons);
  updateAll();
});

$("#pigeonholes").on("change", function() {
  pigeonholes = parseFloat($(this).val());
  $('#outputHVal').html(pigeonholes);
  updateAll();
});

//Getting pigeons
drawPigeons();
drawPigeons();

//Getting target pigeonholes
drawPigeonholes();


// Observations Button
$("#observationsButton").click(function() {
  //Hide button
  $("#button1").hide();
  //Hide Result
  $("#observationsShell").show();
})



/* events fired on the draggable target */
document.addEventListener("drag", function(event) {

}, false);

document.addEventListener("dragstart", function(event) {
  // store a ref. on the dragged elem
  dragged = event.target;
  // make it half transparent
  event.target.style.opacity = 0.5;
}, false);

document.addEventListener("dragend", function(event) {
  // reset the transparency
  event.target.style.opacity = "";
}, false);

/* events fired on the drop targets */
document.addEventListener("dragover", function(event) {
  // prevent default to allow drop
  event.preventDefault();
}, false);

document.addEventListener("dragenter", function(event) {
  // highlight potential drop target when the draggable element enters it
  if (event.target.className == "square") {
    event.target.style.background = "purple";
  }

}, false);

document.addEventListener("dragleave", function(event) {
  // reset background of potential drop target when the draggable element leaves it
  if (event.target.className == "dropzone") {
    event.target.style.background = "";
  }

}, false);

document.addEventListener("drop", function(event) {
  // prevent default action (open as link for some elements)
  event.preventDefault();
  // move dragged elem to the selected drop target
  if (event.target.className == "dropzone") {
    event.target.style.background = "";
   ...