这是我的代码:
boolean keyPressed = true;
boolean mousePressed = true;
PShape circle;
int x;
int y;
void setup() {
background(0);
fullScreen(1);
frameRate(144);
fill(255, 255, 0);
circle = createShape(ELLIPSE, 0, 0, 50, 50);
}
void draw() {
background(0);
if (mousePressed == true) {
noCursor();
}
if (keyPressed == true && key == 'w') {
x = int(random(width));
y = int(random(height));
rect(x, y, 40, 40);
fill(255, 0, 255);
}
if (key == 's') {
background(0);
}
translate(mouseX, mouseY);
shape(circle);
}
当前,当按下W
时,形状会快速显示。我想在形状产生一次的地方使用它,然后在清除背景并再次按下W
时,形状位于其他位置。