int xPos = 100; //variable
int yPos = 100; //variable
void setup() {
size(400,300);
background(0);
noStroke();
frameRate(40); // will make the circles fade in/out slower
}
void draw() {
ellipse(xPos,yPos,20,20);
//background(0);
fill(0,3); //how fast the stars fadein/out
rect(0,0, width, height);// Makes the stars fade in/out and fades the trail
fill(255); // makes the circle color white
ellipse(random(width), random(height),3, 3); //draws the blinking stars
}
void keyPressed()
{
if (keyCode == UP) {
yPos--;
}
else if (keyCode == DOWN) {
yPos++;
}
else if (keyCode == LEFT) {
xPos--;
}
else if (keyCode == RIGHT) {
xPos++;
}else{
println("Wrong key"); //prints "Wrong key" in console anytime a different key than keyCode is pressed
}
}
为什么我的圈子后面有一条小道,所以哪一行代码可以做到这一点?我只想知道是什么类型的代码使它做到了,因为我不知道。
答案 0 :(得分:0)
您正在此处绘制黑色透明背景:
fill(0, 3); //how fast the stars fadein/out
rect(0, 0, width, height);// Makes the stars fade in/out and fades the trail
第一行将颜色设置为黑色透明颜色,第二行在整个窗口上使用该颜色绘制一个矩形。由于它是透明的,因此您仍然会看到以前绘制的内容,但是每一帧都会变得更暗。