
pincel lineal canvas
JavaScript
Actualizado el 17 de Marzo del 2018 por Anonymous (35 códigos) (Publicado el 24 de Septiembre del 2017)
2.498 visualizaciones desde el 24 de Septiembre del 2017

dibuja en linea no en puntitos o cuadros como otros :V
<!DOCTYPE html>
<html>
<body>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
canvas{
display: block;
margin: auto;
}
</style>
<script>
window.onload = function(){
var c = document.createElement("canvas");
c.setAttribute("width", window.innerWidth);
c.setAttribute("height", window.innerHeight);
//c.setAttribute("style", "margin=auto");
lapiz("blue",4)
document.body.appendChild(c);
var ctx = c.getContext('2d');
var pintar;
function lapiz(color,tamaño){
c.onmousedown = function(e) {
ctx.moveTo(e.pageX - c.offsetLeft + tamaño, e.pageY - c.offsetTop);
pintar = true;
};
c.onmousemove = function(e) {
if (pintar) {
ctx.lineTo(e.pageX - c.offsetLeft, e.pageY - c.offsetTop);
ctx.lineWidth = tamaño;
ctx.strokeStyle = color;
ctx.stroke();
}
};
c.onmouseup = function() {
pintar = false;
};
c.onmouseout = function(){
pintar = false;
};
}
};
</script>
</body>
</html>
Comentarios sobre la versión: 0.8 (3)