繁体   English   中英

Processing.js形状不起作用

[英]Processing.js shape not working

我有一个函数,我写了绘制一个具有任意数量的边的多边形。 但是,当我仅在Java脚本中运行它时,它不起作用。 为什么?

    function sketchProc(processing) {

function polygon (sides, centerX, centerY, radius, fillColor, strokeColor) {
    processing.fill(fillColor);
    processing.stroke(strokeColor);
    var innerAngle = 360/sides;
    var rotationAngle = innerAngle;
    processing.beginShape();
    for (var i = 0; i < sides + 2; i++) {
        processing.vertex(centerX + radius*Math.sin(rotationAngle), centerY + radius*Math.cos(rotationAngle));
    console.log(centerX + radius*Math.sin(rotationAngle), centerY + radius*Math.cos(rotationAngle));
        rotationAngle = innerAngle * i;

    }
    processing.endShape();
}}

它只是绘制一个奇怪的锯齿形状。 (我稍后在我的代码中实现了这个功能,它运行正常,只是形状搞砸了。)

将来,您可能希望编辑问题本身而不是仅使用JSFiddle进行注释。 您也可能@reply每个要求它的人。 否则我们不会看到它! 无论如何,谢谢你把它放在一起。

看看这一行:

processing.vertex(centerX + radius*Math.sin(rotationAngle), centerY + radius*Math.cos(rotationAngle));

请注意,您正在将rotationAnglesin()cos()函数。 另请注意, rotationAngle以度为单位指定。 (0到360之间的值。)

这对可汗学院没问题,因为默认情况下他们的功能需要学位。

但是,正常的Processing和Processing.js以弧度为参数! (值介于0到2之间。)因此,您必须将rotationAngle变量转换为弧度值! 你可以使用方便的radians()函数来做到这一点。

更多信息可以在参考资料中找到。

暂无
暂无

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

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