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 class="aligner">
<p id="directions">Use your mouse and draw the shape of Texas from memory.<p>

<div id="calc" style="position:absolute; text-align:center; top:100px; z-index:555; visibility:hidden;">calculating score...</div>

 <div id="results" style="text-align:center; display:inline-block; z-index:555; margin:0 0 300px 0;">
<h2 id="score" style="font-size:2em; padding-left:.3em;"></h2>
<p id="rank" style="font-size:1em;"></p>  
  </div>
  
</div>
<main id="sketch">
  <svg id="svg-drawing" width="1500" height="1500" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" style="overflow:scroll;margin:0;">

    <polyline id="pencil-path" cx="0" cy="0" fill="rgba(0, 0, 0,.5)" fill-rule="inherit"/>
    <path id="smooth-path" d="" />
    <rect id="pencil-point" width="1" height="1" />
    <path id="answer" fill="rgba(0, 0, 0, .1)" d="M0,136.2h66.3l0.9,1.6v-1.6l21.9-0.1L89.6,0h75.1v58.7l2.2,0.5l3,2.8l2.3,2.6l2.3,0.4l1.3-1.3l1.7,0.6l1.7,0.9l0.7-0.4v-2
	l1.4,0.8l1.7,0.4l1,1.7l1.2,2.2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.7l-0.6,2.2l-1.7,0.2c0,0-2.8-0.4-3,0.2c-0.2,0.6-3,0.9-3,0.9s-1.1,1.3-1.3,2.6s-1.7,3.5-1.7,4.1
	c0,0.6-0.7,4.1-0.7,4.1l-0.9,0.9l-0.2,2l-0.6,2l-1.1,0.2h-1.1c0,0-1.2,0.7-1.2,1.2c0,0.6-1.1,2-1.1,2l-0.9,1.5l-2.8,0.2l-2-1.1
	l-2.6-0.2l-3.7-3.7l-3.4-0.7l-1.8-2l-3.2-0.4l-3.7-2.2l-3-2l-1.1-1.7l-1.8-0.7l-2-1.5l-4.5-3.5l-2.1-4.8l-1.2-5.2v-5.2l-3.6-4.3
	l-1.6-5l-1.6-2.8l-3.7-3.5l-6.8-3.5l-3.7-3.7l-2.2-2.8l-2.8-1.3l-2.2-3.5l-4.3-2.9l-2.6-1.7l-3-2.8l-3.2-5.4l-2-1.1l-3-1.8l-2-1.8
	v-3.1H0z" />
    
  </svg>
  
  
</main>

<canvas id="canvas" width="400" height="400" style="display:none; z-index:500; position:relative">
</canvas>
              
            
!

CSS

              
                main {
  width: 100vw;
  height: 100vh;
  position: relative;
  background: #222;
  background: #fff;
  overflow: hidden;
  position:relative;
}

body {
  text-align:center;
  color:#999;
}

#directions{
  position:absolute;
  top:0;
}

.aligner {
  display: flex;
  align-items: center;
  justify-content: center;
      height: 100%;
    width: 100%;
    position: absolute;
    z-index: 1;
}


#svg-drawing {  
  position: absolute;
  top: 0;
  left: 0;  
  width: 1500px;
  height: 1500px;
  z-index: 2;
}

#pencil-path {
  fill: none;
  stroke: rgba(0, 0, 0,.7);
  stroke-width: 2;  
}

#smooth-path {
  fill: none;
  stroke: #fafafa;
  stroke-width: 1;  
}

#answer{
  width:100px;
   left:10px;
    top:20px;
}


              
            
!

JS

              
                var leaderboard = [79, 5, 15, 25, 35, 45, 55, 65, 75, 70, 60, 80, 95, 85, 90, 98, 83];

var y0, x0, y1, x1;

leaderboard.sort(function(a, b){return b-a});


TweenLite.defaultEase = Linear.easeNone;

var perf = window.performance;
var now = perf ? perf.now.bind(perf) : Date.now;
var log = console.log.bind(console);

var pencilPoint = document.querySelector("#pencil-point");
var pencilPath = document.querySelector("#pencil-path");

var answer = document.querySelector("#answer");
var canvas1 = document.getElementById("canvas");
canvas1.width = window.innerWidth;
canvas1.height = window.innerHeight;

var points = [];
var strokes = [];
var prev = null;
var start = 0;

var tl = new TimelineMax();

var pencil = new Draggable(pencilPoint, {
  bounds: "#svg-drawing",
  trigger: "#svg-drawing",
  cursor: "crosshair",
  onDrag,
  onDragEnd,
  onPress
});

function onPress() {
  tl.clear();

  var x = this.pointerX;
  var y = this.pointerY;

  var stroke = {
    elapsed: 0,
    time: start,
    dist: 0,
    x: x,
    y: y
  };

  points = [x, y];
  strokes = [stroke];
  prev = stroke;

  TweenLite.set(pencilPoint, { x, y });
  this.update();
}

function onDrag() {
  //var dist = getDistance(prev, this);
  var x = this.endX;
  var y = this.endY;
  /*
  var stroke = {
    x: x,
    y: y
  }; 
  prev = stroke;
  strokes.push(stroke);*/

  points.push(x, y);

  pencilPath.setAttribute("points", points);
}

function onDragEnd() {
  points.push(points[0], points[1]);
  pencilPath.setAttribute("points", points);

  var box = pencilPath.getBBox();
  var box0 = answer.getBBox();
  var eleWidth = box.width,
      eleHeight = box.height;
  /*
    var scaler = 1
    if(eleWidth/eleHeight >= 1){
      scaler = box0.width/eleWidth;
      pencilPath.setAttribute("transform", "translate("+box.x*-1*scaler+", "+(box.y*-1*scaler+120-box.height*scaler*.5)+") scale("+scaler+")");
    }else{
      scaler = box0.height/eleHeight;
      pencilPath.setAttribute("transform", "translate("+(box.x*-1*scaler+120-box.width*scaler*.5)+", "+box.y*-1*scaler+") scale("+scaler+")");
    }
    */
  //pencilPath.setAttribute("transform", "translate("+box.x*-1*scaler+", "+box.y*-1*scaler+") scale("+scaler+")");
y1 = window.innerHeight * 0.5 - box0.height * 0.5 + 100;
x1 = window.innerWidth * 0.5 - box0.width * 0.5;
  
  answer.setAttribute(
    "transform",
    "translate(" +
    (x1) +
    ", " +
    (y1) +
    ")"
  );
var scaler = 1;
  if(eleWidth/eleHeight >= 1){
      scaler = box0.width/eleWidth;
    }else{
      scaler = box0.height/eleHeight;
    }
  
  var scalerX = scaler;
  var scalerY = scaler;
  x0 = window.innerWidth*.5-box.width*scalerX*.5-box.x;
  y0 = window.innerHeight*.5-box.height*scalerY*.5-box.y;
  /*
  pencilPath.setAttribute(
    "transform",
    "translate(" +
    x0 +
    ", " +
    y0 +
    ") scale(" +
    scalerX +
    "," +
    scalerY +
    ")"
  );
  */
  TweenMax.to(pencilPath, 1, {x:x0, y:(y0+100), scaleX:scalerX, scaleY:scalerY, ease:Cubic.easeInOut});

  // pencilPath.setAttribute("transform", "translate("+box.x*-1*scaleX+", "+box.y*-1*scaleY+") scale("+scaleX+","+scaleY+")");
  TweenMax.fromTo(calc, 1, {autoAlpha:0, y:"50px"}, {autoAlpha:1, y:"0", ease:Cubic.easeInOut});
     TweenMax.to(directions, 1, {alpha:0, ease:Cubic.easeInOut});

  TweenMax.to(answer, 2, {
    fill: "rgba(0, 0, 0,.2)",
    ease: Cubic.easeInOut,
    delay:0,
    onComplete: function() {
      
      var svgText = document.getElementById("svg-drawing").outerHTML;
      var myCanvas = document.getElementById("canvas");
      var ctxt = myCanvas.getContext("2d");

      drawInlineSVG(ctxt, svgText, function() {
        //console.log(canvas.toDataURL());  // -> PNG
        alert("see console for output...");
      });
    }
  });
}

function drawInlineSVG(ctx, rawSVG, callback) {
    var svgURL = new XMLSerializer().serializeToString(document.getElementById("svg-drawing"));

      img2 = new Image();
  //alert(rawSVG);

  img2.onload = function() {
    canvas1.width = 326;
    canvas1.height = 312;
    
    
    
    ctx.drawImage(this, (x1*-1), -94);
        
        var dataURL = canvas1.toDataURL("image/png");
//$('#results').append('<img src="'+dataURL+'"/>')
    
   // domURL.revokeObjectURL(url);
    // callback(this);
    var data = ctx.getImageData(0, 0, canvas1.width, canvas1.height).data;
    for (var ct = 0, ct2 = 0, i = 3, len = data.length; i < len; i += 4) {
      if (data[i] < 140 && data[i] > 80) ct-=1.2;
      if (data[i] < 80 && data[i] > 10) ct-=.6;
      if (data[i] > 140) ct++;
    }
    //44000 - 22000;
    var accuracy = Math.floor((ct)/440);
    if(accuracy < 0) accuracy = 0;
    //alert(ct2 - ct);
    //alert(accuracy + "% accuracy");
    var game = {myscore:0}
       TweenMax.to(calc, 0, {alpha:0, ease:Cubic.easeInOut});
  
    
   TweenMax.to(game, 1, {myscore:accuracy, roundProps:"myscore", onUpdate:updateHandler, onComplete:function(){
     TweenMax.to(score, .2, {scaleX:3, scaleY:3, ease:Back.easeOut}); 

function checkScore(scor) {
    return scor <= accuracy;
}
     var therank = leaderboard.findIndex(checkScore) + 1;
     if(therank == 0){therank = leaderboard.length + 1}
     
  document.getElementById("rank").innerHTML="You ranked "+therank+" out of "+parseInt(leaderboard.length+1);
     TweenMax.from(rank, .2, {scaleX:0, scaleY:0, delay:.2, ease:Back.easeOut}); 
     document.getElementById('sketch').style.zIndex = "0";
     $('.aligner').click(function() {showleaders();});
     
   }});
    
    function showleaders(){
TweenMax.to('#sketch', 1, {autoAlpha:0, y:"-=50", ease:Power2.easeInOut, delay:.1});
      TweenMax.to('#results', 1, {autoAlpha:0, y:"-=50", ease:Power2.easeInOut, delay:0});
    }
                
        function updateHandler() {
      document.getElementById("score").innerHTML= game.myscore + "<sup style='font-size:.5em;'>%</sup>";      
        }    
    //document.getElementById("canvas").style.display = "block";

  };

  img2.src = 'data:image/svg+xml; charset=utf8, '+encodeURIComponent(svgURL);
  //window.open(url, '_blank');
}


              
            
!
999px

Console