Вы захотите применить к этому гораздо более простой подход. Вместо того, чтобы рисовать линию с несколькими точками, вместо этого нарисуйте настоящую линию! И вы также можете использовать только 1 x
.
Это небольшой пример программы, которая выдает следующий результат:
int x = 10, y = 50;
void setup() {
size(400, 400);
rectMode(CENTER); // So the values you give rect() are seen as the center of the rectangle
}
void draw() {
background(255);
drawLine();
drawRectangle();
x += 3;
}
void drawLine() {
strokeWeight(5); // Make the line more visible
line(0, y, x, y); // Draw a line from the left of the screen to x
strokeWeight(1); // Return to standard
}
void drawRectangle() {
fill(255, 0, 0); // Make the color red
rect(x, y, 20, 20); // Draw the rectangle
}
Пример