【问题标题】:draw perfect ellipse(circle) using beginShape in processing在处理中使用 beginShape 绘制完美的椭圆(圆)
【发布时间】:2018-09-29 18:35:22
【问题描述】:

我的 processing.js 草图遇到了速度问题,我想通过使用 beginShape() endShape() 创建我的 25 个椭圆来加快速度。我知道这功能有限,但否则处理将在每个椭圆调用上执行 context.beginPath(),如下所示:

function line (x1, y1, x2, y2) {
  context.beginPath();
  context.moveTo(x1, y1);
  context.lineTo(x2, y2);
  context.closePath();
  context.stroke();
};

如果我能以某种方式创建带有贝塞尔顶点或简单曲线顶点的椭圆,那么我也许能够完成此任务。有没有人以这种方式成功创建圈子?还是有更好的选择?

【问题讨论】:

  • 我非常怀疑你会以这种方式节省任何处理资源 - 处理在绘制其原语方面比用户定义的等价物要好得多。如果你的椭圆真的很小,你可以通过绘制八边形来节省资源。
  • 你是完全正确的。在将我的性能问题归结为每个相互嵌套的循环的几个问题后,我意识到了这一点。原来我没有优化这些循环的最新 processing.js 版本。现在它可以工作了,我的碰撞算法限制了我每帧占用 99% 的计算能力。必须开始寻找创建更好的碰撞图形的方法。

标签: performance processing bezier ellipse


【解决方案1】:
void draw() {
  translate(width/2,height/2);
  drawCircle(10,width/3);
}

void drawCircle(int sides, float r)
{
    float angle = 360 / sides;
    beginShape();
    for (int i = 0; i < sides; i++) {
        float x = cos( radians( i * angle ) ) * r;
        float y = sin( radians( i * angle ) ) * r;
        vertex( x, y);    
    }
    endShape(CLOSE);
}

有代码))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    • 1970-01-01
    • 2012-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多