こんにちは、新しい半径を入力してボタンをクリックすると、新しい円を描きたいと思います。私はマウスでそれを配置するはずです。しかし、私は円を描いた後、私は新しいものを描くことができないか、それともマウスを置くことができません。以前のものを保存しながらクリック位置に新しい円を描く
オプション1:あなたのdraw()
機能からbackground()
関数を呼び出す停止
import interfascia.*;
int numCircles = 500;
Circle[] circles = new Circle[numCircles]; // define the array
int k=0;
GUIController c;
IFButton b1;
IFTextField tn;
float bx;
float by;
boolean overBox = false;
boolean locked = false;
float xOffset = 0.0;
float yOffset = 0.0;
float r;
void setup() {
size(1439,800);
smooth();
noStroke();
bx=width/2;
by=height/2;
c = new GUIController (this);
b1 = new IFButton ("Click to draw", 600, 220, 100);
tn=new IFTextField("", 100,20,50);
c.add(b1);
c.add(tn);
}
void draw() {
background(205);
if (mouseX > bx-r && mouseX < bx+r &&
mouseY > by-r && mouseY < by+r) {
overBox = true;
if(!locked) {
}
} else {
overBox = false;
}
circles[k] = new Circle(bx,by,r);
circles[k].display(); // display all the circles
}
void actionPerformed (GUIEvent e) {
if (e.getSource() == b1) {
r=float(tn.getValue());
}
}
class Circle {
float x,y,r; // location
color c; // color
Circle(float x, float y, float r) {
this.x = x;
this.y = y;
this.r = r;
c = color(random(255));
}
void display() {
ellipse(x,y,10,10); // a circle at position xy
}
}
void mousePressed() {
if(overBox) {
locked = true;
} else {
locked = false;
}
xOffset = mouseX-bx;
yOffset = mouseY-by;
}
void mouseDragged() {
if(locked) {
bx = mouseX-xOffset;
by = mouseY-yOffset;
}
}
void mouseReleased() {
locked = false;
overBox=false;
}
D単に画面をクリアしないでください。 –
メンテナンス可能な変数名でコードスニペットを編集できますか? –
ヒント:変数名に複数の文字を使用することを禁止する法律はうまく書かれていませんでした。単にそれをしないでください。 – GhostCat