jquery - 如何使用css3/canvas沿着边缘旋转六边形

标签 jquery css canvas

我想旋转六边形但不知道如何...

enter image description here

感谢你帮助我!

最佳答案

这实际上是通过缩放而不是旋转完成的。

如果您从这张图片开始:

enter image description here

然后将其宽度缩放到其原始宽度的 50%,你会得到:

enter image description here

下面是关于如何将宽度缩放到 50% 的代码:

// move the canvas origin(0,0) to the center of the canvas

ctx.translate(canvas.width/2,canvas.height/2);

// scale the width to 50% of its original width

ctx.scale(0.50,1);

// finally draw the image, which will be scaled in width

ctx.drawImage(img,-img.width/2,-img.height/2);

所以要创建你的效果:

  • 将橙色和紫色的六边形缩放到 50% 宽度
  • 让他们靠得更近
  • 在其他 2 个六边形之上绘制金色六边形

关于jquery - 如何使用css3/canvas沿着边缘旋转六边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22625839/

相关文章:

javascript - 如何根据另一个div的高度更改一个div的最小高度

Javascript、CSS、jQuery - 我的 Canvas 移动到了不该移动的地方

javascript - 将多个套接字实例绘制到 Canvas 上并在移动时更新(多人游戏)

ruby-on-rails - 如何让 Apache 在 Rails 开发中提供新的 css 文件

javascript - 如何在 Fabric.Text() 中创建 <ul> 或项目符号?

javascript - 您可以下载已经加载的图像吗?

javascript - 三个垂直堆叠的 Div,动态高度

javascript - 将 url 文件夹与标签 href 匹配以使其处于事件状态

javascript - 固定侧边栏对于浏览器来说太高(底部被切断)

html - 无论宽度如何,按钮/选项卡看起来都一样