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

<button>generate</button>

              
            
!

CSS

              
                #map{
  background:black;
}
.tile{
  box-sizing:border-box;
  float:left;
  background:green;
  color:white;
}
.tile[closed="1"]{
  background:blue;
}
              
            
!

JS

              
                $(document).ready(function(){
var tilesize = 32;  
  var mapheight=320;
  var mapwidth=320;
  $('#map').css({'width':mapheight,'height':mapwidth});
  
 $('button').click(function(){
var tile = '<div class="tile"></div>';  
var numtiles=(mapheight/tilesize)*(mapwidth/tilesize);

  $('#map').html('');
   var i;
for (i = 0; i < numtiles; i++) {
    $('#map').append(tile);   $('.tile').css({'width':tilesize,'height':tilesize});   
} 
  
$('.tile').each(function(){
//randomly close or open tiles
var closed = [0, 0, 1][Math.floor(Math.random() * 3)]
  $(this).attr("closed", closed);
});
  
     $('.tile').each(function(){
    var bitsum=0;
       
 if ($(this).attr("closed")==0){
var my_x = $(this).position().left
var my_y = $(this).position().top

var nw = document.elementFromPoint(my_x - tilesize, my_y - tilesize);  
var nn = document.elementFromPoint(my_x, my_y - tilesize);
var ne = document.elementFromPoint(my_x + tilesize, my_y - tilesize);  
var ww = document.elementFromPoint(my_x - tilesize, my_y);
var ee = document.elementFromPoint(my_x + tilesize, my_y);
var sw = document.elementFromPoint(my_x - tilesize, my_y + tilesize);  
var ss = document.elementFromPoint(my_x, my_y + tilesize);
var se = document.elementFromPoint(my_x + tilesize, my_y + tilesize);  
  
var nw_bit=128;
var nn_bit=1;
var ne_bit=2;  
var ww_bit=64;
var ee_bit=4;     
var sw_bit=32;  
var ss_bit=16;  
var se_bit=8; 

if($(nw).attr("closed")==1){nw_bit=0;};   if($(nn).attr("closed")==1){nn_bit=0;};   
if($(ne).attr("closed")==1){ne_bit=0;};     if($(ee).attr("closed")==1){ee_bit=0;};     if($(ww).attr("closed")==1){ww_bit=0;};
if($(sw).attr("closed")==1){sw_bit=0;};     if($(ss).attr("closed")==1){ss_bit=0;};     if($(se).attr("closed")==1){se_bit=0;};

bitsum = nw_bit+nn_bit+ne_bit+ee_bit+ww_bit+sw_bit+ss_bit+se_bit;  
 }else{
    bitsum=256;
 }
$(this).attr("bitsum", bitsum); 

//DEBUG ONLY
//$(this).html(bitsum); 
       
$(this).css('background', 'blue url(https://kylavana.github.io/tileset.gif) no-repeat ' + -bitsum*tilesize + 'px 0px')
       
});       
});
  
});

              
            
!
999px

Console