<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv= "Content-Type" content= "text/html; charset=UTF-8" >
<style type= "text/css" >
body {
margin: 0;
}
#cnvs {
outline: #000000 1px solid;
}
</style>
<script type= "text/javascript" >
var action = "up" ;
//: , , , ,
var canvas,ctx,offset,points,bufer;
//
function initcnvs(){
canvas = document .getElementById( 'cnvs' );
ctx = canvas.getContext( '2d' );
ctx.lineWidth = 10;
// ( )
offset = 1000;
//
ctx.shadowBlur = 10;
ctx.shadowColor = "#000000" ;
ctx.shadowOffsetX = -offset;
points = new Array();
//
bufer = ctx.getImageData(0,0,canvas.width,canvas.height);
};
//
function mDown(e){
action = "down" ;
points.push([e.pageX,e.pageY]);
};
// -
function mUp(e){
action = "up" ;
points = new Array();
bufer = ctx.getImageData(0,0,canvas.width,canvas.height);
};
// -
function mMove(e){
if (action == "down" ) {
ctx.putImageData(bufer,0,0);
points.push([e.pageX,e.pageY]);
ctx.beginPath();
ctx.moveTo(points[0][0]+offset, points[0][1]);
for (i = 1; i < points.length; i++){
ctx.lineTo(points[i][0]+offset,points[i][1]);
}
ctx.stroke();
}
};
</script>
</head>
<body onload= "initcnvs()" onmousedown= "mDown(event)" onmousemove= "mMove(event)" onmouseup= "mUp(event)" >
<canvas id= "cnvs" width= "800" height= "500" ></canvas>
</body>
</html>
* This source code was highlighted with Source Code Highlighter .
Source: https://habr.com/ru/post/119891/