canvas教程

ocanvas 画板

字号+ 作者:H5之家 来源:H5之家 2017-02-03 09:01 我要评论( )

ocanvas 画板,使用ocanvas做了个简单的在线画板。ocanvas参考:http://ocanvas.org/效果如下:主要代码如下:!DOCTYPE htmlhtmlheadmeta charset=UTF-8 /

使用ocanvas做了个简单的在线画板。

ocanvas参考:

效果如下:

主要代码如下:

oCanvas Example; ; $(function(){ $((){ $(); $(); line_color ); mouseDot.fill = line_color; }); $((){ $(); $(); line_size ); mouseDot.radius ); }); }); body, html .tool .tool .color .tool .color div .tool .color div:hover .tool .color .active .tool .size .tool .size div .tool .size div:hover .tool .size .active .tool .size span .btn .btn input ), ctx ); c.width = window.innerWidth; c.height = window.innerHeight; c.addEventListener(); oCanvas.create({ canvas: , background: , fps: 30, disableScrolling: true }); ; ; ; var mouseDot; clearAll(); cs.bind((){ drawBegin(cs.mouse.x, cs.mouse.y); }).bind((){ drawBegin(cs.touch.x, cs.touch.y); }).bind((){ isDraw = false; }).bind((){ drawMove(cs.mouse.x, cs.mouse.y); }).bind((){ drawMove(cs.touch.x, cs.touch.y); }); /* cs.setLoop(function () { mouseDot.x = cs.mouse.x; mouseDot.y = cs.mouse.y; }).start(); */ function drawBegin(x, y) { isDraw = true; xx = x; yy = y; cs.display.arc({ x: x, y: y, radius: line_size / 2, start: 0, end: 360, fill: line_color }); cs.addChild(dot); } function drawMove(x, y) { if (isDraw) { cs.display.line({ start: { x: xx, y: yy }, end: { x: x, y: y }, stroke: line_color, cap: }); cs.addChild(line); xx = x; yy = y; } else { mouseDot.moveTo(x, y); cs.addChild(mouseDot); cs.draw.redraw(); } } function clearAll() { cs.reset(); // 处理鼠标 cs.mouse.hide(); mouseDot = cs.display.arc({ x: -100, y: -100, radius: Math.max(line_size ), start: 0, end: 360, fill: line_color, shadow: }); cs.addChild(mouseDot); }

程序下载:

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • Plastic Canvas Country kitchen helpers

    Plastic Canvas Country kitchen helpers

    2017-02-03 09:03

  • HTML5 canvas 参考手册

    HTML5 canvas 参考手册

    2017-02-02 17:01

  • AndroidBitmap和Canvas学习笔记

    AndroidBitmap和Canvas学习笔记

    2017-02-02 16:03

  • 讲一讲HTML5里的Canvas究竟是个啥

    讲一讲HTML5里的Canvas究竟是个啥

    2017-02-01 18:00

网友点评
"