Wednesday, March 21, 2012

8 bit Mario - Canvas style

I messing around with HTML5 canvas and decided to make an 8 bit mario :-) Here is the JS code for it:


window.onload = function() {
    var canvas = document.getElementById("batman");
    var context = canvas.getContext("2d");
   
    var blackX = [76, 76, 65, 43, 54, 65, 76];
    var blackY = [43, 54, 65, 76, 76, 76, 76];
    
      var tanX = [10, 21, 32, 43, 10, 21, 32, 43, 10, 21, 32, 54, 65, 87, 98, 54, 65, 87, 98, 109, 131, 32, 43, 54, 76, 87, 98, 131, 87, 98, 109, 120, 54, 65, 76, 87, 98, 109, 120, 175, 186, 153, 164, 175, 186, 164, 175];
      var tanY = [10, 10, 10, 10, 21, 21, 21, 21, 32, 32, 32, 43, 43, 43, 43, 54, 54, 54, 54, 54, 54, 65, 65, 65, 65, 65, 65, 65, 76, 76, 76, 76, 87, 87, 87, 87, 87, 87, 87, 120, 120, 131, 131, 131, 131, 142, 142];
        
    var redX = [65, 76, 87, 98, 109, 120, 43, 54, 65, 76, 87, 98, 109, 120, 131, 10, 21, 32, 43, 10, 21, 32, 43, 10, 21, 21, 32, 32, 43, 43, 54, 76, 87, 98, 120, 131, 142, 153, 164, 65, 76, 87, 109, 120, 131, 142, 153, 164, 175, 109, 120, 131, 142, 153, 164, 120];
    var redY = [21, 21, 21, 21, 21, 21, 32, 32, 32, 32, 32, 32, 32, 32, 32, 43, 43, 43, 43, 54, 54, 54, 54, 65, 65, 76, 76, 87, 87, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 109, 109, 109, 109, 109, 109, 109, 109, 109, 109, 120, 120, 120, 120, 120, 120, 131];
   
    var brownX = [109, 120, 131, 120, 142, 109, 120, 142, 131, 142, 10, 21, 10, 21, 10, 21, 32, 10, 21, 32, 153, 10, 21, 32, 142, 153, 164, 153, 164, 175, 164, 175];
    var brownY = [43, 43, 43, 54, 54, 65, 65, 65, 76, 76, 109, 109, 120, 120, 131, 131, 131, 142, 142, 142, 142, 153, 153, 153, 153, 153, 153, 164, 164, 164, 175, 175];
   
    var blueX = [65, 109, 43, 54, 98, 43, 54, 65, 76, 87, 98, 43, 65, 76, 98, 109, 131, 142, 43, 54, 65, 76, 87, 98, 109, 120, 131, 142, 43, 54, 65, 76, 87, 98, 109, 120, 131, 65, 76, 87, 98, 109, 120, 131, 142, 98, 109, 120, 131, 142];
      var blueY = [98, 98, 109, 109, 109, 120, 120, 120, 120, 120, 120, 131, 131, 131, 131, 131, 131, 131, 142, 142, 142, 142, 142, 142, 142, 142, 142, 142, 153, 153, 153, 153, 153, 153, 153, 153, 153, 164, 164, 164, 164, 164, 164, 164, 164, 175, 175, 175, 175, 175];
      
      var yellowX = [54, 87];
      var yellowY = [131, 131];
      
    
      for (var i = 0; i <= blackX.length; i++) {
    context.fillRect(blackX[i],blackY[i],10,10);
    }
    
    context.fillStyle = "tan";
    
    for (var i = 0; i <= tanX.length; i++) {
        context.fillRect(tanX[i],tanY[i],10,10);
      }
    
      context.fillStyle = "red";
      
      for (var i = 0; i <= redX.length; i++) {
        context.fillRect(redX[i],redY[i],10,10);
      }
      
      context.fillStyle = "brown";
      
      for (var i = 0; i <= brownX.length; i++) {
        context.fillRect(brownX[i],brownY[i],10,10);
      }
      
      context.fillStyle = "blue";
      
      for (var i = 0; i <= blueX.length; i++) {
        context.fillRect(blueX[i],blueY[i],10,10);
      }
      
      context.fillStyle = "yellow";
      
      for (var i = 0; i <= yellowX.length; i++) {
        context.fillRect(yellowX[i],yellowZ[i],10,10);
      }
    }

And the Markup:

<!DOCTYPE html> 
<html lang="en"> 
<head>

</head>
<body>
<canvas width="300" height="300" id="batman"></canvas>
</body>
</html>

Tuesday, March 20, 2012

Batman logo in CSS3 - no images

I was playing with the CSS3 rounded corners and thought that a neat challenge to give myself would be to try to create the Batman logo without images.

the markup:

<div id="main_wrap">
    <div id="left_side">
      <div id="left_wing" >
        <div id="left_middle_top" ></div>
        <div id="left_middle_bottom" >
          <div id="left_bottom_one"></div>
          <div id="left_bottom_two"></div>
        </div>
      </div>
    </div>
    <div id="middle">
      <div id="middle_top"></div>
    </div>
    <div id="right_side">
      <div id="right_wing" >
        <div id="right_middle_top" ></div>
        <div id="right_middle_bottom" >
          <div id="right_bottom_one"></div>
          <div id="right_bottom_two"></div>
        </div>
      </div>
    </div>
  </div>

it even kinda looks like a bat just with the markup lol... but this is all nothing without the CSS

    #main_wrap {
      width:80%
      margin:15px auto;
    }
    #left_side #left_wing {
      height:300px
      width:230px;
      background-color:#000000;
      float:left
      position:relative
      left:12px
      -moz-border-radius-bottomleft: 75px 150px
      border-bottom-left-radius: 75px 150px
      -moz-border-radius-topleft: 75px 150px
      border-top-left-radius: 75px 150px
    }
    #left_side #left_middle_top {
      height:130px
      width:200px
      background-color:#ffffff
      float:left
      z-index:10
      position:relative
      left:40px;
      -moz-border-radius-bottomleft: 120px 120px
      border-bottom-left-radius: 120px 120px
      -moz-border-radius-bottomright: 100px 120px
      border-bottom-right-radius: 100px 120px
      -moz-border-radius-topleft: 100px 120px
      border-top-left-radius: 100px 120px
    }
    #left_side #left_bottom_one {
      height:130px
      width:95px
      background-color:#ffffff
      float:left
      z-index:10
      position:relative
      left:40px
      top:40px;
      -moz-border-radius-bottomleft: 90px 120px
      border-bottom-left-radius: 90px 120px
      -moz-border-radius-topright: 90px 120px
      border-top-right-radius: 90px 120px
      -moz-border-radius-topleft: 90px 120px
      border-top-left-radius: 90px 120px
    }
    #left_side #left_bottom_two {
      height:150px
      width:126px
      background-color:#ffffff
      z-index:11
      position:relative
      float:left
      top:50px
      left:40px;
      -moz-border-radius-topright: 90px 120px
      border-top-right-radius: 90px 120px
      -moz-border-radius-topleft: 90px 120px
      border-top-left-radius: 90px 120px
    }
    #middle{
      width:90px
      height:300px
      background-color:#000000
      float:left
      z-index:5
      position:relative
    }
    #middle #middle_top {
      height:50px
      width:38px
      background-color:#ffffff
      z-index:10
      position:relative
      float:left
      left:26px
      -moz-border-radius-bottomleft: 25px 150px
      border-bottom-left-radius: 25px 150px;
      -moz-border-radius-bottomright: 25px 150px
      border-bottom-right-radius: 25px 150px;
    } 
    #right_side #right_wing {
      height:300px
      width:230px
      background-color:#000000;
      float:left
      position:relative
      left:-12px;
      -moz-border-radius-bottomright: 75px 150px
      border-bottom-right-radius: 75px 150px
      -moz-border-radius-topright: 75px 150px
      border-top-right-radius: 75px 150px
    }
    #right_side #right_middle_top {
      height:130px
      width:200px
      background-color:#ffffff
      float:right
      z-index:10
      position:relative
      right:40px;
      -moz-border-radius-bottomright: 90px 120px
      border-bottom-right-radius: 90px 120px
      -moz-border-radius-bottomleft: 90px 120px
      border-bottom-left-radius: 90px 120px
      -moz-border-radius-topright: 90px 120px
      border-top-right-radius: 90px 120px
    }
    #right_side #right_bottom_one {
      height:130px
      width:95px
      background-color:#ffffff
      float:right
      z-index:10
      position:relative
      right:40px
      top:40px;
      -moz-border-radius-bottomright: 90px 120px
      border-bottom-right-radius: 90px 120px
      -moz-border-radius-topright: 90px 120px
      border-top-right-radius: 90px 120px
      -moz-border-radius-topleft: 90px 120px
      border-top-left-radius: 90px 120px
    }
    #right_side #right_bottom_two {
      height:150px
      width:126px
      background-color:#ffffff
      z-index:11
      position:relative
      float:right
      top:50px
      right:40px;
      -moz-border-radius-topright: 90px 120px
      border-top-right-radius: 90px 120px
      -moz-border-radius-topleft: 90px 120px
      border-top-left-radius: 90px 120px
    }

which gives you the completed image of: