java仅为一个函数使用后台
我正在制作一部关于processing的动画。然后,我有一个关于代码的问题。通常,我的代码比较长。然而,我做了一个简单的代码,它也可以对初学者有用。我的示例代码:
int x1 = 0;
int x2 = 0;
void setup() {
size(500, 100); // create a screen
}
void draw() {
background(255);
drawRectangle();
drawPoint();
}
void drawRectangle() {
rect(x1, 20, 20, 20); // rect(x, y, width,height);
x1 +=5;
}
void drawPoint() {
point(x2, 20); // point(x, y);
x2++;
}
所以,我有点和矩形在同一个方向上。{
# 1 楼答案
你会想用一种更简单的方法来解决这个问题。与其画一条有多个点的线,不如画一条实际的线!你也只能使用1
x
这是一个小示例程序,它生成以下输出: