76 lines
1.4 KiB
HTML
76 lines
1.4 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||
|
<html xmlns="http://www.w3c.org/1999/xhtml">
|
||
|
<head>
|
||
|
<title>CanvasDraw :: Paintbrush</title>
|
||
|
<style type='text/css'>
|
||
|
* {
|
||
|
margin:0;
|
||
|
padding:0;
|
||
|
}
|
||
|
|
||
|
canvas {
|
||
|
position:absolute;
|
||
|
top:50%;
|
||
|
left:50%;
|
||
|
margin-top:-200px;
|
||
|
margin-left:-320px;
|
||
|
border:1px solid #000;
|
||
|
}
|
||
|
</style>
|
||
|
<script type='text/javascript'>
|
||
|
function getwh() {
|
||
|
if (self.innerHeight) {
|
||
|
h=self.innerHeight
|
||
|
w=self.innerWidth
|
||
|
}
|
||
|
else if (document.documentElement && document.documentElement.clientHeight) {
|
||
|
h=document.documentElement.clientHeight
|
||
|
w=document.documentElement.clientHeight
|
||
|
}
|
||
|
else if (document.body) {
|
||
|
h=document.body.clientHeight
|
||
|
w=document.body.clientWidth
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function ani() {
|
||
|
var ctx = document.getElementById('canvas').getContext('2d');
|
||
|
|
||
|
if (click) {
|
||
|
ctx.beginPath()
|
||
|
ctx.moveTo(ox,oy)
|
||
|
ctx.lineTo(x,y)
|
||
|
ctx.stroke()
|
||
|
}
|
||
|
ox=x
|
||
|
oy=y
|
||
|
|
||
|
setTimeout("ani()",1)
|
||
|
}
|
||
|
|
||
|
function load() {
|
||
|
x=0
|
||
|
y=0
|
||
|
ox=0
|
||
|
oy=0
|
||
|
click=false
|
||
|
|
||
|
ani()
|
||
|
}
|
||
|
|
||
|
function mm(e) {
|
||
|
getwh()
|
||
|
x=Math.floor(e.pageX-(w-642)/2-2)
|
||
|
y=Math.floor(e.pageY-(h-402)/2-2)
|
||
|
}
|
||
|
|
||
|
window.onload=load
|
||
|
document.onmousemove=mm
|
||
|
document.onmousedown=function(){click=true}
|
||
|
document.onmouseup=function(){click=false}
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
<canvas id='canvas' width='640' height='400'></canvas>
|
||
|
</body>
|
||
|
</html>
|