Works if unsaved, error if saved
in
Programming Questions
•
10 months ago
Hi guys,
i'm understanding deeper the power of java, and after reading this page i've tryed something, but i encounter in a error. i think the code was good, but when i compile receive this error: "The costructor atoms(float,float,float,float) is undefined"
but is defined it in the atoms class!
PS: sometime it works until you saved the sketch, is it a bug?
i'm understanding deeper the power of java, and after reading this page i've tryed something, but i encounter in a error. i think the code was good, but when i compile receive this error: "The costructor atoms(float,float,float,float) is undefined"
but is defined it in the atoms class!
PS: sometime it works until you saved the sketch, is it a bug?
- int n = 10;
atoms []h = new atoms[n];
void setup() {
size(300, 300);
for (int i=0; i<n; i++){
h[i] = new atoms(random(width), random(height), random(-5, 5), random(-5, 5));
}
}
void draw() {
background(0);
for (int i=0; i<n; i++){
h[i].update();
h[i].display();
}
}
class atom {//contiene le variabili degli atomi
float px, py, vx, vy;
}
class atoms extends atom {//contiene funzioni degli atomi(utilizzando le variabili)
atoms(float a, float b, float c, float d) {
px = a;
py = b;
vx = c;
vy = d;
}
void display() {
point(px, py);
}
void update() {
if (px+vx>width || px+vx<0)vx*=-1;
if (py+vy>height || py+vy<0)vy*=-1;
px+=vx;
py+=vy;
}
}
1