我试图实现一些更精美的画布,例如看起来更像画笔描边的东西。我遇到了令人敬畏的资源(http://perfectionkills.com/exploring-canvas-drawing-techniques/),但我有一些麻烦将它转换为与easeljs一起使用的语法。
原始示例:http://codepen.io/kangax/pen/FdlHC
我的尝试:http://codepen.io/mcfarljw/pen/Jifzk
var currentPoint = { x: event.stageX, y: event.stageY };
var dist = distanceBetween(lastPoint, currentPoint);
var angle = angleBetween(lastPoint, currentPoint);
drawingCanvas.graphics.setStrokeStyle(5, 'round', 'round');
for (var i = 0; i < dist; i += 5) {
x = lastPoint.x + (Math.sin(angle) * i);
y = lastPoint.y + (Math.cos(angle) * i);
drawingCanvas.graphics.beginRadialGradientStroke(["#F00","#00F"], [0, 1], x, y, 5, x, y, 10)
}
lastPoint = currentPoint;
stage.update();
它没有产生任何错误,但它也没有在画布上绘制任何东西。关于我做错了什么的指示?谢谢!
答案 0 :(得分:0)
您的版本已基本完成,预计您错过了实际绘制(当前部分)行的最重要部分:
drawingCanvas.graphics.moveTo(lastPoint.x, lastPoint.y);
drawingCanvas.graphics.lineTo(currentPoint.x, currentPoint.y);
如果您在此处更新了代码笔:http://codepen.io/anon/pen/fCcEJ