简体   繁体   English

HTML5画布的素描效果

[英]Sketching effect with HTML5 canvas

I have a JPEG image consisting of handedly-sketched contours of a city. 我有一个JPEG图像,由一个城市的轮廓轮廓组成。 I want to achieve a slowly-sketching effect drawing these contours on an empty area from left to right. 我想实现缓慢绘制效果,将这些轮廓从左到右绘制在空白区域上。 How can I do that based on the HTML5 canvas element? 如何基于HTML5 canvas元素执行此操作? Something like importing this JPEG into the canvas an applying some animated mask on it or alternatively re-factoring the JPEG into a set of curves (if it's possible I'd like to get a list of appropriate tools) and drawing these lines by using the simple-stupid ctx.lineTo(...) and other curve functions. 诸如将JPEG导入画布,在其上应用一些动画蒙版或将JPEG重新分解为一组曲线(如果可能的话,我想获得适当的工具列表),然后使用简单笨拙的ctx.lineTo(...)和其他曲线函数。

Thank you in advance. 先感谢您。

A while back I was showing someone how to make the effect of an animated hand-drawn line on Canvas. 不久前,我向人们展示了如何在Canvas上制作动画手绘线效果。 The drawing technique drew just a little more of the image each frame, which seems to do pretty much what you would want. 绘图技术每帧只画了一点点图像,这似乎可以完成您想要的任何事情。 In other words: 换一种说法:

var amount = 1;
function drawMore() {
    ctx.clearRect(0,0,can.width, can.height);
    ctx.drawImage(can2, 0, 0, can.width, amount, 0, 0, can.width, amount);
    amount++;
}
setInterval(drawMore, 90);

Will draw none of the image, then it will draw the top row of pixels, then it will draw the top two rows of pixels, etc. Have a look: 将不绘制任何图像,然后绘制像素的最上面一行,然后绘制像素的最上面两行,等等。看看:

http://jsfiddle.net/GfGVE/28/ http://jsfiddle.net/GfGVE/28/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM