我正在創建一個正弦波,我希望可以通過鼠標調整振幅和頻率,所以我製作了一個可以打開和關閉此按鈕的按鈕。它似乎沒有工作。 //Button Script
部分是定義按鈕的地方,它應該可以工作,但是當我在運行它時在框中單擊時,即使我已滿足if
中的所有條件,它也不會執行任何操作。按鈕在處理正弦波項目時不工作
void setup(){ size(1600,900); }
//Define variables.
float amp = 0.0;
float freq = 0;
int totalwavelength = 50;
int mouse = 0;
void draw(){
background(0);
freq = 0;
while (freq < totalwavelength) {
//When button is not pressed, run this script:
if (mouse == 0) {
fill(255);
ellipse(freq * 50 + 20, sin(amp) * 100 + 450, 20, 20);
freq += 1;
amp += 0.5;
//Create Button
fill(255);
rect(800, 800, 200, 100);
//Mouse Coordinates
fill(255, 0, 0);
text("X=" + mouseX, mouseX, mouseY - 10);
text("Y=" + mouseY, mouseX, mouseY);
//Button script
if (mouseX >700 && mouseX < 900 && mouseY >750 && mouseY < 850 && mousePressed == true && mouse == 0) {
mouse = 1;
}
if (mouseX >700 && mouseX < 900 && mouseY >750 && mouseY < 850 && mousePressed == true && mouse == 1) {
mouse = 0;
}
}
//When button pressed run this script:
if (mouse == 1) {
fill(255);
ellipse(freq * 50 + 20, sin(amp) * 100 + 450, 20, 20);
freq += mouseX;
amp += mouseY;
//Create Button
fill(255);
rect(800, 800, 200, 100);
//Button script
if (mouseX >700 && mouseX < 900 && mouseY >750 && mouseY < 850 &&
mousePressed == true && mouse == 0) {
mouse = 1;
}
if (mouseX >700 && mouseX < 900 && mouseY >750 && mouseY < 850 &&
mousePressed == true && mouse == 1){
mouse = 0;
}
}
}
}
非常感謝! –