<code>window.onload=
function
(){
var
ocanvas=document.getElementById(
'canvas'
);
var
ocolor=document.getElementById(
'color'
);
var
obrushSize=document.getElementById(
'brushSize'
);
var
ocontrol=document.getElementById(
'control'
);
var
omakeImage=document.getElementById(
'makeImage'
);
new
Canvas(ocanvas,ocolor,obrushSize,ocontrol,omakeImage);
}
function
Canvas(){
this.init.apply(this,arguments);
}
Canvas.prototype={
preArray:[],
midArray:[],
nextArray:[],
array_paint:[],
config:{
lineWidth:1,
lineColor:
"red"
,
shadowBlur:2
},
init:
function
(oCanvas,oColor,oBrushSize,oControl,oMakeImage){
this.canvas=oCanvas;
this.context=oCanvas.getContext(
'2d'
);
this.color=oColor;
this.brushSize=oBrushSize;
this.control=oControl;
this.makeImage=oMakeImage;
this.initDraw();
this.Draw(oCanvas);
},
initDraw:
function
(){
var
data=this.context.getImageData(0,0,600,500);
this.midArray.push(data);
},
Draw:
function
(canvas){
var
_this=this;
canvas.onmousedown=
function
(e){
var
x=e.offsetX;
var
y=e.offsetY;
canvasX=x,
canvasY=y;
_this.context.beginPath();
_this.context.moveTo(canvasX, canvasY);
var
preData=_this.context.getImageData(0,0,600,500);
_this.preArray.push(preData);
canvas.onmousemove=
function
(e){
var
x1=e.offsetX,
y1=e.offsetY,
canvasX1=x1;
canvasY1=y1;
if
(e.target==_this.canvas){
_this.context.lineTo(canvasX1,canvasY1);
_this.context.stroke();
}
else
{
}
}
};
},
setDrawStyle:
function
(){
this.context.lineWidth=this.config.lineWidth;
this.context.strokeStyle=this.config.lineColor;
this.context.shadowColor=this.config.lineColor;
this.context.shadowBlur=this.config.shadowBlur;
}
};</code>