首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >卧式自行车帆布

卧式自行车帆布
EN

Stack Overflow用户
提问于 2014-04-09 14:10:25
回答 1查看 217关注 0票数 0

我试着创造水平圆柱体。我已经找到了下面的链接,这是用来创建垂直圆柱。

How to draw a cylinder on html5 canvas

有人能告诉我发生的变化来创建一个水平的圆筒吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-09 16:00:45

通常,如果有要旋转的绘图,则可以使用转换。

转换画布的移动、旋转(和缩放),而不需要对所需的绘图进行重新编码。

演示:http://jsfiddle.net/m1erickson/RU26r/

此转换将使原始绘图旋转90度:

代码语言:javascript
复制
drawRotatedCylinder(100,100,50,30,90);

function drawRotatedCylinder(x,y,w,h,degreeAngle){

  // save the context in its unrotated state
  context.save();

  // translate to the rotation point
  // your object will rotate around the rotation point
  // so if you want it to rotate from the center then 
  // translate to x+width/2, y+height/2

  context.translate(x+w/2,y+h/2);

  // rotate by 90 degrees
  // rotate() takes radians, so convert to radians
  // with radians==degrees*Math.PI/180

  context.rotate(degreeAngle*Math.PI/180);

  // draw your original shape--no recoding required!

  drawCylinder(-w/2,-h/2,w,h);

  // restore the context to its untransformed state

  context.restore();

}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22965237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档