tadr
YaBB Newbies
Offline
Posts: 18
classes and arrays
Aug 25th , 2009, 6:16pm
i am trying to store the coordinates of each krosnja object so that i can use them, but what i get is coordinates for all 10 objects i initiated. i don't know how can i separate them and compare the coordinates later. what i am trying to do is to compare the x,y from k[0] object and k[1...etc]. like : dist(x(k[0]), y(k[0]), x1(k[1]), y1(k[1]) if someone can help that would be great. thanks! int currentk =0; int numb = 10; int xmos, ymos; krosnja[] k = new krosnja[numb]; //float[]x = new float[numb]; //float[]y = new float[numb]; void setup(){ size(1000,600); background(255); smooth(); frameRate(25); stroke(0); strokeWeight(0.7); for (int i =0; i < numb; i++){ k[i] = new krosnja(); k[i].kros(random(width), random(height), random(3)); } } void draw(){ //if (keyCode == UP){ for(int i = 0; i<numb; i++){ k[i].crtaj(); } } void mousePressed(){ xmos = mouseX; ymos = mouseY; k[currentk].kros(xmos, ymos, random(3)); currentk++; if (currentk >= numb){ currentk = 0; } } class krosnja{ float xa, ya, step, stepx, stepy; float[]x = new float[numb]; float[]y = new float[numb]; float[][]xy = { x,y }; float di; int x1, y1, x2, y2; void kros(float xxx, float yyy, float stp){ xa = xxx; ya = yyy; step = stp; } void crtaj(){ stepx = step; stepy = step; point(xa,ya); xa=xa+stepx*random(-1,1); ya=ya+stepy*random(-1,1); if (xa > width-50){ stepx = -step; xa = width-50; } else if (xa < 0){ xa = 10; stepx = step; } else if (ya > height -50){ ya = height - 50; stepy = -step; } else if (ya < 0){ ya = 10; stepy = step; } } }