简体   繁体   English

带有圆角的EaselJS三角形?

[英]EaselJS triangle with rounded corners?

How can I create a triangle with rounded corners in EaselJS? 如何在EaselJS中创建带有圆角的三角形? I'm using drawPolyStar to create the triangle, 我正在使用drawPolyStar创建三角形,

var polystar = new createjs.Shape();
polystar.graphics.drawPolyStar(100, 100, 60, 3, 0, -90);

This is an image of what I want the triangle to look like: 这是我希望三角形看起来像的图像: 结果与预期三角形

EDIT: Image link doesn't seem to work. 编辑:图像链接似乎不起作用。 This is what the triangle should look like : 这是三角形的样子: 在此处输入图片说明

But actual triangle has sharp corners. 但是实际的三角形有尖角。

There are no canvas APIs for rounding corners of polygons that works like the roundRect API. 没有工作于roundRect API的用于圆角多边形的canvas API。

There are a few approaches I can think of: 我可以想到几种方法:

  1. Do the round corners yourself using arcTo. 使用arcTo自己制作圆角。 This would take some math to figure out, and there may even be some libraries or examples floating around. 这需要一些数学运算才能弄清楚,甚至可能还有一些库或示例随处可见。

[EDIT] I spent a little time making a sample https://jsfiddle.net/lannymcnie/cga60tsf/1/ [编辑]我花了一些时间制作示例https://jsfiddle.net/lannymcnie/cga60tsf/1/

  1. Using rounded stroke edges, you can sort of fake it. 使用圆形的笔触边缘,您可以对其进行伪造。 This fiddle shows how a thick line with round ends can make the outer edges look round. 该小提琴显示了带有圆形末端的粗线如何使外边缘看起来是圆形的。 You could draw another smaller triangle on top to give the desired effect. 您可以在顶部绘制另一个较小的三角形,以获得所需的效果。

Sample 样品

// Line outer radius
context.lineJoin = "round";
context.lineWidth = cornerRadius;

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

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