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 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

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 id="stage">
</div>

              
            
!

CSS

              
                BODY {
  background: #000000;
}

#stage {
position: relative;
margin: 0px auto;
background: #87e0fd;
background: -moz-linear-gradient(top,  #87e0fd 0%, #53cbf1 40%, #05abe0 100%);
background: -webkit-linear-gradient(top,  #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
background: linear-gradient(to bottom,  #87e0fd 0%,#53cbf1 40%,#05abe0 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#87e0fd', endColorstr='#05abe0',GradientType=0 );
  width: 900px;
  height: 400px;
  border-radius: 10px;
}

.tile {
  position: absolute;
  width: 50px;
  height: 50px;
  background-color:#07b313;
  border-radius: 10px;
}

.coin {
  position: absolute;
  width: 30px;
  height: 30px;
  margin: 10px;
  background-color:#E0E800;
  border-radius: 50%;
}
              
            
!

JS

              
                //Level Generator - www.101computing.net
var rows = 8;
var cols = 18;
var grid = [
  [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0],
  [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0],
  [0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0],
  [0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0],
  [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0],
  [1,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0],
  [0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0],
  [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];

function displayLevel() {
  var stage = document.getElementById("stage");
  for (var row = 0; row < rows; row++) {
    for (var col = 0; col < cols; col++) {
      if (grid[row][col]==2) {
          var coin = document.createElement('div');
          coin.className = "coin";
          coin.style.top = row*50 + 'px';
          coin.style.left = col*50 + 'px';
          stage.appendChild(coin);
      } else if (grid[row][col]==1) {
          var tile = document.createElement('div');
          tile.className = "tile";
          tile.style.top = row*50 + 'px';
          tile.style.left = col*50 + 'px';
          //Merge tiles which are next to each other
          if (col<cols-1) { if (grid[row][col+1]==1) {tile.style.borderBottomRightRadius='0px';tile.style.borderTopRightRadius='0px';}}
          if (col>0) { if (grid[row][col-1]==1) {tile.style.borderBottomLeftRadius='0px';tile.style.borderTopLeftRadius='0px';}}
          if (row<rows-1) { if (grid[row+1][col]==1) {tile.style.borderBottomLeftRadius='0px';tile.style.borderBottomRightRadius='0px';}}
          if (row>0) { if (grid[row-1][col]==1) {tile.style.borderTopLeftRadius='0px';tile.style.borderTopRightRadius='0px';}}
           //Add tile to the stage
           stage.appendChild(tile);
       }  
     }
   } 
}


displayLevel();
              
            
!
999px

Console