Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="generator">
  <h1>
    <span>Random Teams</span> Generator
  </h1>
  <form id="form">
    <div>
      <label class="method-label method-2" for="teams-labels">Teams' Names</label>
      <p>one per line or comma separated</p>
      <textarea id="teams-labels" cols="20" rows="1" name="teams-labels" autofocus>Peaches, Greens, Sandies</textarea>            
    </div>
    <div class="members">
      <label for="teams-members">Members' Names</label>
      <p>one per line or comma separated</p>
      <textarea id="teams-members" cols="20" rows="5" name="teams-members">Anthony, Layla, Daniela, Murielle, Louis, Florian, Marc, Ryan, Kesia, Margot, Amandine</textarea>
    </div>
    <button type="submit" id="submit" class="submit">Go!</button>
  </form>
  <div class="results" id="results">
    <div class="finalteams" id="finalteams"></div>
    <button class="copy" type="button" id="copy">copy</button>
  </div>
</div>

              
            
!

CSS

              
                :root {
  --green: #A2CCB6;
  --yellow: #FCEEB5;
  --peach: #EE786E;
}
* {
  box-sizing: border-box;
}
html {
  font-family: Coiny, sans-serif;
  line-height: 1.5;
  background: var(--yellow);
  color: var(--peach);
  overflow-y: scroll;
  min-height: 100%;
}
body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

p {
  font-family: Thasadith, sans-serif;
  font-weight: 700;
  margin: 0
}

label+p {
  margin: -0.5rem 0 .5rem;
}

h1, h2 {
  font-weight: 400;
}
h2 {
  margin-bottom: 0;
}
h1 {
  text-align: center;
  font-size: calc(2rem + 4vw);
  line-height: 1;
  text-shadow: 1px 1px 0 var(--yellow), 2px 2px 0 var(--yellow), 3px 3px 0 currentColor, 4px 4px 0 currentColor;
}
h1 span {
  text-shadow: 1px 1px 0 var(--yellow), 2px 2px 0 var(--yellow), 3px 3px 0 currentColor, 4px 4px 0 currentColor;
}
label,
button,
textarea {
  font-family: inherit;
  font-size: 1.5rem;
}

textarea {
  padding: .75rem 1.5rem;
  background: var(--peach);
  color: var(--yellow);
  border: none;
  border-radius: 10px; 
  width: 100%;
  position: relative;
}

.generator{
  margin: 0 auto;
  width: 90%;
  max-width: 960px;
}

h1 span,
.members,
button {
  color: var(--green);
}
.members textarea {
  background: var(--green);
}

form {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
form > div {
  width: 100%;
}
@media screen and (min-width: 960px) {
  form > div {
    flex: 1 0 calc(50% - .5rem);
    max-width: calc(50% - .5rem);
  }
}

button {
  border-radius: 10px;
  cursor: pointer;
}
button[type="submit"] {
  width: 100%;
  padding: 0.75rem;
  border: 3px solid;
  background: transparent;
  position: relative;
  margin-top: 1rem;
  transition: 0.25s ease-in;
}
button[type="submit"]:before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: var(--green);
  opacity: .3;
  z-index: -1;
  transform: translate3d(6px, 6px, 0);
  border-radius: 7px;
  transition: inherit;
}
button:focus {
  outline: none;
}
button[type="submit"]:hover,
button[type="submit"]:focus {
  color: var(--yellow); 
}
button[type="submit"]:hover:before,
button[type="submit"]:focus:before {
  opacity: 1;
  transform: translate3d(0,0,0);
}

textarea:focus {
  outline: none; 
  box-shadow: inset 0 0 0 3px currentcolor, inset 3px 3px 0 4px var(--yellow), 3px 3px 0 #f7c49c, 4px 4px 0 #f7c49c;
  background: #f7c49c;
  color: var(--peach);
}

.members textarea:focus {
  box-shadow: inset 0 0 0 3px currentcolor, inset 3px 3px 0 4px var(--yellow), 3px 3px 0 #e1e4b6, 4px 4px 0 #e1e4b6;
  background: #e1e4b6;
  color: var(--green);
}

.finalteams {
  visibility: hidden;
  opacity: 0;
  transition: opacity ease-in .5s;
}
.finalteams:not(:empty) {
  margin: 2rem auto;
  background: var(--yellow);
  border-radius: 10px;
  padding: 2rem;
  border: 3px solid var(--peach);
  box-shadow: 1px 1px 0 var(--peach), 2px 2px 0 var(--peach), 3px 3px 0 var(--peach);
}

section:first-of-type h2 {
  margin: 0;
}

canvas {
  display: block;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: -10;
}
.results {
  position: relative;
}
.copy {
  border: none;
  background: var(--peach);
  color: var(--yellow);
  position: absolute;
  top: 1rem;
  right: 1rem;
  visibility: hidden;
  opacity: 0;
  transition: .5s .5s;
}
.copy:hover,
.copy:focus {
  color: var(--peach);
  box-shadow: 0 0 0 3px;
  background: transparent;
}
.finalteams:not(:empty),
.finalteams:not(:empty) + .copy  {
  visibility: visible;
  opacity: 1;
}
              
            
!

JS

              
                'use strict';

const form = document.getElementById("form");
const teamLabelsTextarea =  document.getElementById("teams-labels");
const teamMembersTextarea = document.getElementById( "teams-members" );

let shuffle = function( array ) {
	array.sort(function(a, b){return 0.5 - Math.random()});
}

let lottery = function( members, groupNames ) {
 
  let current = 0, teams = Array();
  const modulo = members.length % groupNames.length;
  const minPerGroup = Math.floor(members.length / groupNames.length );
  const maxPerGroup = Math.floor(members.length / groupNames.length ) + (modulo > 0);  
  shuffle( members );
  for ( let i = 0; i<groupNames.length; i++) {
    if ( i < modulo || modulo === 0 ) {
      teams.push(members.slice(i*(maxPerGroup), (i+1)*(maxPerGroup)));
    } else {
      teams.push(members.slice((maxPerGroup*modulo+(i-modulo)*minPerGroup), (maxPerGroup*modulo+(i-modulo+1)*minPerGroup)));
    }
  }  
  return groupMembersByLabels( teams, groupNames );
}

let groupMembersByLabels = function( teamsArray, labelsArray ) {
  let constitution = {};
  shuffle(labelsArray);
  for ( let i = 0; i < labelsArray.length; i++ ) {
    constitution[labelsArray[i]] = teamsArray[i];
  }
  return constitution;
}

let toArray = function( string ) {
  string = string.trim();
  string = string.replace(/\n/g, ",");
  let array = string.split(",");
  array = array.filter(function(entry) { return entry.trim() != ''; });
  return array;
};

let addCopyListener = function() {
  const copyButton = document.getElementById('copy');
  copyButton.addEventListener('click', () => {
    const selection = window.getSelection();
    const range = document.createRange();
    range.selectNodeContents(document.getElementById('finalteams'));
    selection.removeAllRanges();
    selection.addRange(range);
    try {
      document.execCommand('copy');
      selection.removeAllRanges();
      const original = copyButton.textContent;
      copyButton.textContent = 'copied!'; 
      setTimeout(() => {
        copyButton.textContent = original;
      }, 1000);
    } catch(e) {
      console.log(e);
    }
  });
}

let displayResults = function(teams, where, teamsArray) {   
  let inner = '';
  const originalLabels = toArray( teamLabelsTextarea.value );
  for ( let i =0 ; i < originalLabels.length; i++ ) {
    let property = originalLabels[i];
    inner += `<section><h2>${property} </h2><p>`;
    for (let i=0; i<teams[property].length; i++) {
       inner += `<span>${teams[property][i]}</span>`;
      if (i < teams[property].length - 1) {
        inner += ', ';
      }
    }
     inner += ` (${teams[property].length})</p></section>`;
  }
    where.innerHTML = inner;
}

addCopyListener();

form.addEventListener( "submit", function( event ) {  
  event.preventDefault();
  const namesArray = toArray( teamMembersTextarea.value );
  const teamsArray = toArray( teamLabelsTextarea.value );
  const teams = lottery( namesArray, teamsArray );
  displayResults( teams, document.getElementById("finalteams"), teamsArray );
});


// Credits Bouncing random balls by Roberto Pérez https://codepen.io/todomagichere/pen/BqeMvd Thank you!

//Gravity
(function() {
  var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
                              window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  window.requestAnimationFrame = requestAnimationFrame;
})();

let canvas = document.createElement('canvas');
canvas.id = 'screen';
document.body.appendChild(canvas);
canvas.width = 2*window.innerWidth;
canvas.height = 2*window.innerHeight;
canvas.style.width = "100vw";
canvas.style.height = "100vh";
var screenWidth = canvas.width/2;
var screenHeight = canvas.height/2;
var ctx = canvas.getContext("2d");
ctx.scale(2,2);
var fps = 90;
var interval = 1000/fps;
var lastTime = (new Date()).getTime();
var currentTime = 0;
var delta = 0;

function mainLoop() {
    window.requestAnimationFrame(mainLoop);

    currentTime = (new Date()).getTime();
    delta = (currentTime - lastTime);

    if (delta > interval) {
        ctx.fillStyle = "#FCEEB5";
        ctx.fillRect(0, 0, screenWidth, screenHeight);
        draw();
        controlBall();
        lastTime = currentTime - (delta % interval);
    }
}

function controlBall() {
    if (randomNumber(1,100) < 2) {
        ballArray.push(new Ball());            
    }
    if (ballArray.length === 40) {
        for (var i = 0; i < 20; i++) {
            ballArray.shift();
        }
    }    
}

function draw() {
    drawBall();
}

var ballArray = [];
var colorArray = ["#EE786E", "#A2CCB6"];
var gravity = 0.9;

function drawBall() {
    for (var i = 0; i < ballArray.length; i++) {
        var ball = ballArray[i];
        ctx.fillStyle = ball.color;
        ctx.beginPath();
        ctx.arc(ball.x, ball.y, ball.radius, 0, Math.PI * 2);
        ctx.fill();
        ctx.closePath();
        
        ball.x += ball.xd;
        if (ball.x + ball.radius > screenWidth || ball.x - ball.radius < 0) {
            ball.xd *= -1;
        }
        
        ball.gravitySpeed += gravity;
        ball.y += (ball.yd + ball.gravitySpeed);
        if (ball.y + ball.radius > screenHeight) {
            if (ball.xd !== 0) {
                ball.xd *= ball.friction  ;
            }
            ball.y = screenHeight - ball.radius;
            ball.gravitySpeed = -(ball.gravitySpeed * ball.bounce);
        }
    }
}

function Ball() {
    this.radius = randomNumber(5, 20);
    this.color = colorArray[randomNumber(0, colorArray.length -1)];
    this.x = randomNumber(this.radius, screenWidth - this.radius);
    this.y = -this.radius;
    this.yd = 0;
    this.xd = randomNumber(-5, 5);
    this.gravitySpeed = 0;
    this.bounce = 0.8;
    this.friction = 0.99;
    return this;
}

function randomNumber(min, max) {
    return Math.floor(Math.random() * (max - min + 1) + min);
};

mainLoop();
              
            
!
999px

Console