我有一个函数,我写了绘制一个多边形与任何数量的边。但是,当我只用Java脚本运行它时,它不起作用。为什么?Processing.js形状不工作
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或运行您的代码的CodePen吗? –
@KevinWorkman当我输入时,canvas和外部脚本不起作用。 –
我不确定你在说什么。我们需要能够运行代码。做到这一点的最佳方式是将JSFiddle或CodePen放在一起。 –