Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                // checkbox to turn CSSimon on or off
<input type="checkbox" id="cb-onoff" hidden />

// radio buttons to indicate the id of the sequence (one only for now)
<input type="radio" id="sequence-0" class="sequence" name="sequence" checked hidden />

// radio buttons that indicate current round within the sequence
- var r = 0;
while r < 31
  input(type="radio", id="round-"+r, class="round", name="round", checked=(r==0), value=r++, hidden)

// radio buttons to keep track of the current step within the round
- var r = 0;
while r < 31
  - var s = 0;
  while s <= r
    input(type="radio", id="round-"+r+"-step-"+s, name="round-"+r, checked=(s==0), value=s++, hidden)
  - r++

// radio buttons to detect if a mistake was made by the player
<input type="radio" id="correct" name="correct-incorrect" checked hidden/>
<input type="radio" id="incorrect" name="correct-incorrect" hidden />

// CSSimon board
<div id="simon">
  // four incorrect buttons
  <label class="button button-1 incorrect" for="incorrect"></label>
  <label class="button button-2 incorrect" for="incorrect"></label>
  <label class="button button-3 incorrect" for="incorrect"></label>
  <label class="button button-4 incorrect" for="incorrect"></label>
  
  // sequence of labels for right steps for each round
  - var sequence = [1,2,3,4,1,1,3,4,2,3,1,2,4,3,3,2,4,1,1,4,4,4,2,3,2,1,4,2,3,1];
  - var r = 0;
  while r < 31
    - var s = 0;
    while s <= r
      if (r == s)
        label(class="button button-"+sequence[s]+" correct round-"+r+" step-"+s, for="round-"+(r+1))
      else 
        label(class="button button-"+sequence[s]+" correct round-"+r+" step-"+s, for="round-"+r+"-step-"+(s+1))
      - s++
    - r++
  <!-- 1 2 3 4 1 1 3 4 2 3 1 2 4 3 3 2 4 1 1 4 4 4 2 3 2 1 4 2 3 1 -->
  
  // center of board
  <div id="center">
    <div id="card">
      <h1>CSSimon</h1>
      <h2>by Alvaro Montoro</h2>
      <div id="onoff">
        <label id="switch" for="cb-onoff"></label>
      </div>
    </div>
  </div>
  <div id="protector"></div>
</div>

// game over message
<div id="gameover">
  <div>Oh no! You Lost!</div>
  <div>Reload the page to start again!</div>
</div>

// game over message
<div id="youwon">
  <div>Yes! You Won!</div>
  <div>Reload the page to start again!</div>
</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Exo+2:400,900');

html,body {
 background: #ccc;  
}

#gameover, #youwon {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: rgba(0,0,0,0.7);
  color: white;
  display: none;
  div {
    text-align: center;
    margin: 3vmin;
    font-size: 4vmin;
    font-family: "exo 2", "exo2", "exo", arial, sans-serif;
  }
}

#simon {
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  width: 50vmin;
  height: 50vmin;
  background: #333;
  border-radius: 100%;
  box-shadow: inset 0.5vmin 0.5vmin 0.75vmin rgba(255,255,255,0.2),
              inset 1vmin 1vmin 0.75vmin rgba(0,0,0,0.15),
              inset -0.5vmin -0.5vmin 0.75vmin rgba(0,0,0,0.2),
              inset -0.75vmin -0.75vmin 0.75vmin rgba(255,255,255,0.1),
              0.5vmin 0.5vmin 1.5vmin rgba(0,0,0,0.2);
  overflow: hidden;
  aborder: 2vmin outset rgba(255,255,255,0.1);
  box-sizing: border-box;
}

#protector {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  z-index: 4;
}

#center, #card {
  width: 40%;
  height: 40%;
  background: #333;
  position: absolute;
  border-radius: 100%;
  top: 50%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  z-index: 5;
}

#card {
  width: 80%;
  height: 80%;
  background: #bbb;
  text-align: center;
}

#onoff {
  position: absolute;
  width: 30%;
  height: 15%;
  background: #222;
  border-radius: 1000px;
  position: absolute;
  top: 65%;
  left: 35%;
  box-shadow:inset 0 0 10px 0 black;
}

#switch {
  position: absolute;
  top: 7%;
  left: 7%;
  width: 43%;
  height: 86%;
  background: #999;
  border-radius: 100%;
  display: inline-block;
  transition: left 0.5s;
  cursor: pointer;
}

#cb-onoff:checked ~ #simon #switch {
  left: 53%;
}

h1, h2 {
  font-family: "exo 2", "exo2", "exo", arial, sans-serif;
  font-size: 3vmin;
  margin-top:0;
  position: absolute;
  top: 35%;
  left: 50%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
  color: #222;
  font-weight: 900;
  user-select: none;
}

h2 {
  font-size: 1.5vmin;
  top: 50%;
  font-weight: 400;
  white-space: nowrap;
}

#simon label.button {
  position: absolute;
  width: 43%;
  height: 43%;
  border: 0;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.2);
  outline: none;
  cursor: pointer;
  transition: all 0.25s;
  animation-timing-function: linear;
  animation-fill-mode: backwards;
  animation-delay: 0.5s;
}

label.button.incorrect {
  z-index: 2;
}

label.button.correct {
  z-index: 1;
  background: transparent;
  box-shadow: 0 0 0 0 rgba(0,0,0,0) !important;
}

.button-1 { 
  top: 5%; 
  left: 5%; 
  border-radius: 100% 2% 2% 2%;
  background: #4c6;
  box-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
.button-2 { 
  top: 5%; 
  right: 5%; 
  border-radius: 2% 100% 2% 2%;
  background: #c44;
}
.button-3 { 
  bottom: 5%; 
  left: 5%; 
  border-radius: 2% 2% 2% 100%;
  background: #dd6;
}
.button-4 { 
  bottom: 5%; 
  right: 5%; 
  border-radius: 2% 2% 100% 2%;
  background: #46c;
}

#cb-onoff:checked {
  ~ #simon {
    .button-1:active { background: #6e8; }
    .button-2:active { background: #e66; }
    .button-3:active { background: #ff8; }
    .button-4:active { background: #68e; }
    #protector { z-index: 1; }
  }
  @for $i from 0 through 10 { // 30 {
    @for $s from 0 through $i {
      ~ #round-#{$i}:checked ~ #round-#{$i}-step-#{$s}:checked ~ #simon .round-#{$i}.step-#{$s} { z-index: 3; }
    }
  }
}

$sequence: 1 2 3 4 1 1 3 4 2 3 1 2 4 3 3 2 4 1 1 4 4 4 2 3 2 1 4 2 3 1;
$colors: #4c6 #7f9, #c44 #f77, #dd6 #ff9, #46c #79f;
@each $i in [1,2,3,4] {
  @for $s from 1 through 30 {
     @keyframes sequence-0-step-#{$s - 1}-button-#{$i} {
       0% { background: nth(nth($colors, $i), 1); }
       @for $m from 1 through $s {
         #{100 * ($m - 1) / $s + 1}% { 
           @if nth($sequence, $m) == $i {
             background: nth(nth($colors, $i), 2);
           } @else {
             background: nth(nth($colors, $i), 1); 
           }
         }
         #{100 * $m / $s - 1}% { 
           @if nth($sequence, $m) == $i {
             background: nth(nth($colors, $i), 2);
           } @else {
             background: nth(nth($colors, $i), 1);
           }
         }
         #{100 * $m / $s - 0.5}% { 
           background: nth(nth($colors, $i), 1);
         }
       }
       100% { background: nth(nth($colors, $i), 1); }
    }
  }
}

// 1,2,3,4,1
@for $s from 0 through 0 {
  @for $i from 0 through 30 {
    @for $j from 1 through 4 {
      #cb-onoff:checked ~ #sequence-#{$s}:checked ~ #round-#{$i}:checked ~ #simon .button-#{$j} { 
        animation-name: sequence-#{$s}-step-#{$i}-button-#{$j};
        animation-duration: #{$i*0.5 + 1}s;
      }
    }
  }
}

@for $i from 0 through 1 {
  @keyframes protect-buttons-#{$i} {
    0% { z-index: 1 }
    1% { z-index: 4 }
    99% { z-index: 4 }
    100% { z-index: 1 }
  }
}

@for $s from 0 through 0 {
  @for $i from 0 through 30 {
    #cb-onoff:checked ~ #sequence-#{$s}:checked ~ #round-#{$i}:checked ~ #simon #protector {
      animation-name: protect-buttons-#{$i % 2};
      animation-duration: #{$i*0.5 + 1.5}s;
    }
  }
}

#incorrect:checked ~ {
  #simon #protector {
    z-index: 5;
  }
  #gameover {
    display: block;
  }
}

#round-30:checked ~ #youwon {
  display: block;
}

@each $i in [1,2,3,4] {
  @keyframes incorrect-button-#{$i} {
    0% { background: nth(nth($colors, $i), 2) }
    20% { background: nth(nth($colors, $i), 2) }
    21% { background: nth(nth($colors, $i), 1) }
    40% { background: nth(nth($colors, $i), 1) }
    41% { background: nth(nth($colors, $i), 2) }
    60% { background: nth(nth($colors, $i), 2) }
    61% { background: nth(nth($colors, $i), 1) }
    80% { background: nth(nth($colors, $i), 1) }
    81% { background: nth(nth($colors, $i), 2) }
    99% { background: nth(nth($colors, $i), 2) }
    100% { background: nth(nth($colors, $i), 1) }
  }
  #incorrect:checked {
    ~ #simon .button-#{$i} {
      animation-delay: 0s;
      animation-name: incorrect-button-#{$i} !important;
      animation-duration: 1s !important;
    }
  }
}
              
            
!

JS

              
                // https://i.imgur.com/YsbKHg1.gif
              
            
!
999px

Console