Difference between revisions of "Team:SVCE Chennai/Notebook"

Line 230: Line 230:
 
      
 
      
 
     <script>
 
     <script>
   
+
(function() {
(function() {
+
 
+
  // Dimensions of the whole book
// Dimensions of the whole book
+
  var BOOK_WIDTH = 830;
var BOOK_WIDTH = 830;
+
  var BOOK_HEIGHT = 560;
var BOOK_HEIGHT = 560;
+
 
+
  // Dimensions of one page in the book
// Dimensions of one page in the book
+
  var PAGE_WIDTH = 400;
var PAGE_WIDTH = 400;
+
  var PAGE_HEIGHT = 550;
var PAGE_HEIGHT = 550;
+
 
+
  // Vertical spacing between the top edge of the book and the papers
// Vertical spacing between the top edge of the book and the papers
+
  var PAGE_Y = (BOOK_HEIGHT - PAGE_HEIGHT) / 2;
var PAGE_Y = ( BOOK_HEIGHT - PAGE_HEIGHT ) / 2;
+
 
+
  // The canvas size equals to the book dimensions + this padding
// The canvas size equals to the book dimensions   this padding
+
  var CANVAS_PADDING = 60;
var CANVAS_PADDING = 60;
+
 
+
  var page = 0;
var page = 0;
+
 
+
  var canvas = document.getElementById("pageflip-canvas");
var canvas = document.getElementById( "pageflip-canvas" );
+
  var context = canvas.getContext("2d");
var context = canvas.getContext( "2d" );
+
 
+
  var mouse = {
var mouse = { x: 0, y: 0 };
+
    x: 0,
+
    y: 0
var flips = [];
+
  };
+
 
var book = document.getElementById( "book" );
+
  var flips = [];
+
 
// List of all the page elements in the DOM
+
  var book = document.getElementById("book");
var pages = book.getElementsByTagName( "section" );
+
 
+
  // List of all the page elements in the DOM
for( var i = 0, len = pages.length; i < len; i   ) {
+
  var pages = book.getElementsByTagName("section");
pages[i].style.zIndex = len - i;
+
 
+
  for (var i = 0, len = pages.length; i < len; i++) {
flips.push( {
+
    pages[i].style.zIndex = len - i;
// Current progress of the flip (left -1 to right 1)
+
 
progress: 1,
+
    flips.push({
// The target value towards which progress is always moving
+
      // Current progress of the flip (left -1 to right +1)
target: 1,
+
      progress: 1,
// The page DOM element related to this flip
+
      // The target value towards which progress is always moving
page: pages[i],  
+
      target: 1,
// True while the page is being dragged
+
      // The page DOM element related to this flip
dragging: false
+
      page: pages[i],
} );
+
      // True while the page is being dragged
}
+
      dragging: false
+
    });
// Resize the canvas to match the book size
+
  }
canvas.width = BOOK_WIDTH   ( CANVAS_PADDING * 2 );
+
 
canvas.height = BOOK_HEIGHT   ( CANVAS_PADDING * 2 );
+
  // Resize the canvas to match the book size
+
  canvas.width = BOOK_WIDTH + (CANVAS_PADDING * 2);
// Offset the canvas so that it's padding is evenly spread around the book
+
  canvas.height = BOOK_HEIGHT + (CANVAS_PADDING * 2);
canvas.style.top = -CANVAS_PADDING   "px";
+
 
canvas.style.left = -CANVAS_PADDING   "px";
+
  // Offset the canvas so that it's padding is evenly spread around the book
+
  canvas.style.top = -CANVAS_PADDING + "px";
// Render the page flip 60 times a second
+
  canvas.style.left = -CANVAS_PADDING + "px";
setInterval( render, 1000 / 60 );
+
 
+
  // Render the page flip 60 times a second
document.addEventListener( "mousemove", mouseMoveHandler, false );
+
  setInterval(render, 1000 / 60);
document.addEventListener( "mousedown", mouseDownHandler, false );
+
 
document.addEventListener( "mouseup", mouseUpHandler, false );
+
  document.addEventListener("mousemove", mouseMoveHandler, false);
+
  document.addEventListener("mousedown", mouseDownHandler, false);
function mouseMoveHandler( event ) {
+
  document.addEventListener("mouseup", mouseUpHandler, false);
// Offset mouse position so that the top of the book spine is 0,0
+
 
mouse.x = event.clientX - book.offsetLeft - ( BOOK_WIDTH / 2 );
+
  function mouseMoveHandler(event) {
mouse.y = event.clientY - book.offsetTop;
+
    // Offset mouse position so that the top of the book spine is 0,0
}
+
    mouse.x = event.clientX - book.offsetLeft - (BOOK_WIDTH / 2);
+
    mouse.y = event.clientY - book.offsetTop;
function mouseDownHandler( event ) {
+
  }
// Make sure the mouse pointer is inside of the book
+
 
if (Math.abs(mouse.x) < PAGE_WIDTH) {
+
  function mouseDownHandler(event) {
if (mouse.x < 0 && page - 1 >= 0) {
+
    // Make sure the mouse pointer is inside of the book
// We are on the left side, drag the previous page
+
    if (Math.abs(mouse.x) < PAGE_WIDTH) {
flips[page - 1].dragging = true;
+
      if (mouse.x < 0 && page - 1 >= 0) {
}
+
        // We are on the left side, drag the previous page
else if (mouse.x > 0 && page   1 < flips.length) {
+
        flips[page - 1].dragging = true;
// We are on the right side, drag the current page
+
      } else if (mouse.x > 0 && page + 1 < flips.length) {
flips[page].dragging = true;
+
        // We are on the right side, drag the current page
}
+
        flips[page].dragging = true;
}
+
      }
+
    }
// Prevents the text selection
+
 
event.preventDefault();
+
    // Prevents the text selection
}
+
    event.preventDefault();
+
  }
function mouseUpHandler( event ) {
+
 
for( var i = 0; i < flips.length; i   ) {
+
  function mouseUpHandler(event) {
// If this flip was being dragged, animate to its destination
+
    for (var i = 0; i < flips.length; i++) {
if( flips[i].dragging ) {
+
      // If this flip was being dragged, animate to its destination
// Figure out which page we should navigate to
+
      if (flips[i].dragging) {
if( mouse.x < 0 ) {
+
        // Figure out which page we should navigate to
flips[i].target = -1;
+
        if (mouse.x < 0) {
page = Math.min( page   1, flips.length );
+
          flips[i].target = -1;
}
+
          page = Math.min(page + 1, flips.length);
else {
+
        } else {
flips[i].target = 1;
+
          flips[i].target = 1;
page = Math.max( page - 1, 0 );
+
          page = Math.max(page - 1, 0);
}
+
        }
}
+
      }
+
 
flips[i].dragging = false;
+
      flips[i].dragging = false;
}
+
    }
}
+
  }
+
 
function render() {
+
  function render() {
+
 
// Reset all pixels in the canvas
+
    // Reset all pixels in the canvas
context.clearRect( 0, 0, canvas.width, canvas.height );
+
    context.clearRect(0, 0, canvas.width, canvas.height);
+
 
for( var i = 0, len = flips.length; i < len; i   ) {
+
    for (var i = 0, len = flips.length; i < len; i++) {
var flip = flips[i];
+
      var flip = flips[i];
+
 
if( flip.dragging ) {
+
      if (flip.dragging) {
flip.target = Math.max( Math.min( mouse.x / PAGE_WIDTH, 1 ), -1 );
+
        flip.target = Math.max(Math.min(mouse.x / PAGE_WIDTH, 1), -1);
}
+
      }
+
 
// Ease progress towards the target value  
+
      // Ease progress towards the target value  
flip.progress = ( flip.target - flip.progress ) * 0.2;
+
      flip.progress += (flip.target - flip.progress) * 0.2;
+
 
// If the flip is being dragged or is somewhere in the middle of the book, render it
+
      // If the flip is being dragged or is somewhere in the middle of the book, render it
if( flip.dragging || Math.abs( flip.progress ) < 0.997 ) {
+
      if (flip.dragging || Math.abs(flip.progress) < 0.997) {
drawFlip( flip );
+
        drawFlip(flip);
}
+
      }
+
 
}
+
    }
+
 
}
+
  }
+
 
function drawFlip( flip ) {
+
  function drawFlip(flip) {
// Strength of the fold is strongest in the middle of the book
+
    // Strength of the fold is strongest in the middle of the book
var strength = 1 - Math.abs( flip.progress );
+
    var strength = 1 - Math.abs(flip.progress);
+
 
// Width of the folded paper
+
    // Width of the folded paper
var foldWidth = ( PAGE_WIDTH * 0.5 ) * ( 1 - flip.progress );
+
    var foldWidth = (PAGE_WIDTH * 0.5) * (1 - flip.progress);
+
 
// X position of the folded paper
+
    // X position of the folded paper
var foldX = PAGE_WIDTH * flip.progress   foldWidth;
+
    var foldX = PAGE_WIDTH * flip.progress + foldWidth;
+
 
// How far the page should outdent vertically due to perspective
+
    // How far the page should outdent vertically due to perspective
var verticalOutdent = 20 * strength;
+
    var verticalOutdent = 20 * strength;
+
 
// The maximum width of the left and right side shadows
+
    // The maximum width of the left and right side shadows
var paperShadowWidth = ( PAGE_WIDTH * 0.5 ) * Math.max( Math.min( 1 - flip.progress, 0.5 ), 0 );
+
    var paperShadowWidth = (PAGE_WIDTH * 0.5) * Math.max(Math.min(1 - flip.progress, 0.5), 0);
var rightShadowWidth = ( PAGE_WIDTH * 0.5 ) * Math.max( Math.min( strength, 0.5 ), 0 );
+
    var rightShadowWidth = (PAGE_WIDTH * 0.5) * Math.max(Math.min(strength, 0.5), 0);
var leftShadowWidth = ( PAGE_WIDTH * 0.5 ) * Math.max( Math.min( strength, 0.5 ), 0 );
+
    var leftShadowWidth = (PAGE_WIDTH * 0.5) * Math.max(Math.min(strength, 0.5), 0);
+
 
+
    // Change page element width to match the x position of the fold
// Change page element width to match the x position of the fold
+
    flip.page.style.width = Math.max(foldX, 0) + "px";
flip.page.style.width = Math.max(foldX, 0)   "px";
+
 
+
    context.save();
context.save();
+
    context.translate(CANVAS_PADDING + (BOOK_WIDTH / 2), PAGE_Y + CANVAS_PADDING);
context.translate( CANVAS_PADDING   ( BOOK_WIDTH / 2 ), PAGE_Y   CANVAS_PADDING );
+
 
+
    // Draw a sharp shadow on the left side of the page
+
    context.strokeStyle = 'rgba(0,0,0,' + (0.05 * strength) + ')';
// Draw a sharp shadow on the left side of the page
+
    context.lineWidth = 30 * strength;
context.strokeStyle = 'rgba(0,0,0,' (0.05 * strength) ')';
+
    context.beginPath();
context.lineWidth = 30 * strength;
+
    context.moveTo(foldX - foldWidth, -verticalOutdent * 0.5);
context.beginPath();
+
    context.lineTo(foldX - foldWidth, PAGE_HEIGHT + (verticalOutdent * 0.5));
context.moveTo(foldX - foldWidth, -verticalOutdent * 0.5);
+
    context.stroke();
context.lineTo(foldX - foldWidth, PAGE_HEIGHT   (verticalOutdent * 0.5));
+
 
context.stroke();
+
    // Right side drop shadow
+
    var rightShadowGradient = context.createLinearGradient(foldX, 0, foldX + rightShadowWidth, 0);
+
    rightShadowGradient.addColorStop(0, 'rgba(0,0,0,' + (strength * 0.2) + ')');
// Right side drop shadow
+
    rightShadowGradient.addColorStop(0.8, 'rgba(0,0,0,0.0)');
var rightShadowGradient = context.createLinearGradient(foldX, 0, foldX   rightShadowWidth, 0);
+
 
rightShadowGradient.addColorStop(0, 'rgba(0,0,0,' (strength*0.2) ')');
+
    context.fillStyle = rightShadowGradient;
rightShadowGradient.addColorStop(0.8, 'rgba(0,0,0,0.0)');
+
    context.beginPath();
+
    context.moveTo(foldX, 0);
context.fillStyle = rightShadowGradient;
+
    context.lineTo(foldX + rightShadowWidth, 0);
context.beginPath();
+
    context.lineTo(foldX + rightShadowWidth, PAGE_HEIGHT);
context.moveTo(foldX, 0);
+
    context.lineTo(foldX, PAGE_HEIGHT);
context.lineTo(foldX   rightShadowWidth, 0);
+
    context.fill();
context.lineTo(foldX   rightShadowWidth, PAGE_HEIGHT);
+
 
context.lineTo(foldX, PAGE_HEIGHT);
+
    // Left side drop shadow
context.fill();
+
    var leftShadowGradient = context.createLinearGradient(foldX - foldWidth - leftShadowWidth, 0, foldX - foldWidth, 0);
+
    leftShadowGradient.addColorStop(0, 'rgba(0,0,0,0.0)');
+
    leftShadowGradient.addColorStop(1, 'rgba(0,0,0,' + (strength * 0.15) + ')');
// Left side drop shadow
+
 
var leftShadowGradient = context.createLinearGradient(foldX - foldWidth - leftShadowWidth, 0, foldX - foldWidth, 0);
+
    context.fillStyle = leftShadowGradient;
leftShadowGradient.addColorStop(0, 'rgba(0,0,0,0.0)');
+
    context.beginPath();
leftShadowGradient.addColorStop(1, 'rgba(0,0,0,' (strength*0.15) ')');
+
    context.moveTo(foldX - foldWidth - leftShadowWidth, 0);
+
    context.lineTo(foldX - foldWidth, 0);
context.fillStyle = leftShadowGradient;
+
    context.lineTo(foldX - foldWidth, PAGE_HEIGHT);
context.beginPath();
+
    context.lineTo(foldX - foldWidth - leftShadowWidth, PAGE_HEIGHT);
context.moveTo(foldX - foldWidth - leftShadowWidth, 0);
+
    context.fill();
context.lineTo(foldX - foldWidth, 0);
+
 
context.lineTo(foldX - foldWidth, PAGE_HEIGHT);
+
    var foldGradient = context.createLinearGradient(foldX - paperShadowWidth, 0, foldX, 0);
context.lineTo(foldX - foldWidth - leftShadowWidth, PAGE_HEIGHT);
+
    foldGradient.addColorStop(0.35, '#fafafa');
context.fill();
+
    foldGradient.addColorStop(0.73, '#eeeeee');
+
    foldGradient.addColorStop(0.9, '#fafafa');
+
    foldGradient.addColorStop(1.0, '#e2e2e2');
+
 
var foldGradient = context.createLinearGradient(foldX - paperShadowWidth, 0, foldX, 0);
+
    context.fillStyle = foldGradient;
foldGradient.addColorStop(0.35, '#fafafa');
+
    context.strokeStyle = 'rgba(0,0,0,0.06)';
foldGradient.addColorStop(0.73, '#eeeeee');
+
    context.lineWidth = 0.5;
foldGradient.addColorStop(0.9, '#fafafa');
+
 
foldGradient.addColorStop(1.0, '#e2e2e2');
+
    context.beginPath();
+
    context.moveTo(foldX, 0);
context.fillStyle = foldGradient;
+
    context.lineTo(foldX, PAGE_HEIGHT);
context.strokeStyle = 'rgba(0,0,0,0.06)';
+
    context.quadraticCurveTo(foldX, PAGE_HEIGHT + (verticalOutdent * 2), foldX - foldWidth, PAGE_HEIGHT + verticalOutdent);
context.lineWidth = 0.5;
+
    context.lineTo(foldX - foldWidth, -verticalOutdent);
+
    context.quadraticCurveTo(foldX, -verticalOutdent * 2, foldX, 0);
+
 
context.beginPath();
+
    context.fill();
context.moveTo(foldX, 0);
+
    context.stroke();
context.lineTo(foldX, PAGE_HEIGHT);
+
 
context.quadraticCurveTo(foldX, PAGE_HEIGHT   (verticalOutdent * 2), foldX - foldWidth, PAGE_HEIGHT   verticalOutdent);
+
    context.restore();
context.lineTo(foldX - foldWidth, -verticalOutdent);
+
  }
context.quadraticCurveTo(foldX, -verticalOutdent * 2, foldX, 0);
+
 
+
context.fill();
+
context.stroke();
+
+
+
context.restore();
+
}
+
+
 
})();
 
})();
  
 
     </script>
 
     </script>
 
</html>
 
</html>

Revision as of 20:55, 17 September 2015

Notebook

Primitive Cats Poem

Like primitives we buried the cat with his bowl. Bare-handed.We scraped sand and gravel back into the hole.They fell with a hiss and thud on his side, on his long red fur, the white feathers between his toes, and his long, not to say aquiline, nose.

We stood and brushed each other off. There are sorrows keener than these. Silent the rest of the day, we worked, ate, stared, and slept. It stormed all night; now it clears, and a robin burbles from a dripping bush like the neighbor who means well but always says the wrong thing.

A Poem to End

Life is like a box of chocolates, Sweet and full of surprise. If only you knew what was in for you, when your given the gift of life.

Life is like a box of chocolates, a wonder for a child, but as you grow, your more likely to know, which chocolates will be vile.

Life is like a box of chocolates, you never know what your gonna get, but when in strife, and confused with life, there'll always be a treat, so don't fret.

Lets talk!

Sri Venkateswara College of Engineering, Chennai