在P5J中绘制平滑线
我的功能创建了一个函数,该函数从其第一个参数的坐标中绘制了一条线,并将其绘制为第二个参数的坐标。代码使用鼠标坐标作为该函数的参数运行该函数。但是,我遇到一个问题,即垂直移动鼠标光标会导致行不均匀。
let circles = [];
function setup() {
createCanvas(600, 600);
}
function draw() {
lineCreate([pmouseX,pmouseY],[mouseX,mouseY])
}
function lineCreate(point1, point2) {
length = sqrt(pow(point2[0]-point1[0],2) + pow(point2[1]-point1[1],2))
slope = (point2[1]-point1[1])/(point2[0]-point1[0])
x = min(point1[0],point2[0])
endX = max(point1[0],point2[0])
for (let i = x; i < endX; i++) {
pointSlope = slope*(i - point1[0]) + point1[1]
circle(i,pointSlope,2,2)
}
}
I have a function that I created which draws a line from the coordinates of its first argument to the coordinates of the second argument. The code runs the function using the mouse coordinates as the argument for the function. However, I am having an issue where moving the mouse cursor vertically will cause the line to be uneven.
let circles = [];
function setup() {
createCanvas(600, 600);
}
function draw() {
lineCreate([pmouseX,pmouseY],[mouseX,mouseY])
}
function lineCreate(point1, point2) {
length = sqrt(pow(point2[0]-point1[0],2) + pow(point2[1]-point1[1],2))
slope = (point2[1]-point1[1])/(point2[0]-point1[0])
x = min(point1[0],point2[0])
endX = max(point1[0],point2[0])
for (let i = x; i < endX; i++) {
pointSlope = slope*(i - point1[0]) + point1[1]
circle(i,pointSlope,2,2)
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将点与行连接:
如果您想用各个点绘制界线,则需要区分沿x轴还是y轴之间的距离较大:
You need to connect the dots with lines:
If you want to draw the line with individual points, you need to distinguish whether the distance between the points is larger along the x-axis or the y-axis: