Ich bin eine Sinuswelle erstellen und ich möchte die Amplitude und Frequenz mit der Maus einstellbar sein, also habe ich eine Schaltfläche, die dies ein- und ausgeschaltet. Es scheint nicht zu funktionieren. Der //Button Script
Teil ist, wo die Schaltfläche definiert ist, und es sollte funktionieren, aber wenn ich in das Feld klicke, während es ausgeführt wird, tut es nichts, obwohl ich alle Bedingungen in if
erfüllt habe.Button funktioniert nicht auf einem Sinus-Projekt in Bearbeitung
void setup() { Größe (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;
}
}
}
}
Vielen Dank! –