안녕하세요 새로운 반지름을 입력하고 버튼을 클릭하면 새로운 서클을 그립니다. 나는 그것을 마우스로 배치해야한다. 그러나 원을 그리면 새 것을 그릴 수 없으며 마우스를 배치 할 수도 없습니다.이전 위치를 저장하면서 클릭 위치에 새로운 서클 그리기
옵션 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