【发布时间】:2021-09-30 16:36:24
【问题描述】:
我正在使用 beginShape() 和 endShape() 函数在 P5JS 中绘制曲线。在向我的形状(一条线)添加点时,我通过curveVertex() 函数这样做。但是,由于某种原因,最终曲线不会在points[0] 和points[1] 之间创建一个段。如果我改为通过vertex() 函数将点添加到曲线中,则第一段 被绘制。相关代码:
function draw() {
// Loop through creating line segments
beginShape()
noFill()
// Add the first point
stroke('black')
strokeWeight(5)
curveVertex(x, y)
// Save points, draw last
let points = []
points.push({x: x, y: y})
// Draw line
for (let i = 0; i < segments; i++){
// Get random y
yRand = random(-(height * 0.125), height * 0.125);
// Add point to curve
curveVertex(x += length / segments, y += yRand);
// Save point
points.push({x: x, y: y})
}
// Draw Last Point
curveVertex(x, y)
endShape()
// Draw the last point & segment
stroke('#ff9900')
strokeWeight(10)
points.push({x: x, y: y})
points.forEach(function(p){
point(p.x, p.y)
})
// Draw the line once and stop
noLoop();
}
这会产生以下图像:
您可以看到 points[0] 和 points1 之间的缺失段。现在,如果我在代码中的三个位置将curveVertex() 替换为vertex(),我会得到以下图像:
如您所见,第一段是在这里绘制的。如果我使用endShape(CLOSE),我会使用curveVertex 模式获得第一段——但也会在points[0] 和points[-1] 之间画一条线(这是不需要的行为)
我的问题:vertex() 和 curveVertex() 之间有什么区别会省略第一段?
【问题讨论】:
标签: javascript processing p5.js