spooky
YaBB Newbies
Offline
Posts: 1
Array....achtung!!!!!
Apr 16th , 2009, 9:18am
I have a problem with this sketch...I have not idea how make to display each element of a String in each particle...I have almost architect, no informatic, becaus i newby in P5...Somebody have an idea??? //---------------- LIBRERIAS ---------------------------------------// import point2line.*; //----------------- VARIABLES GLOBALES ------------------------------------// PFont fuente; Particula [] particula = new Particula [6]; Vect2 [] posicion = new Vect2 [6]; //----------------------------------------------------------// void setup(){ size(640, 400); smooth(); noStroke(); fuente = loadFont("Arial-Black-9.vlw"); textFont(fuente); textAlign(CENTER); textSize(6); for(int i = 0; i < posicion.length;i++){ posicion = new Vect2 (random(width),random(height)); } for(int i = 0; i < particula.length; i++){ particula[i] = new Particula(posicion,new Vect2(2,2)); } } //----------------------------------------------------------// void draw(){ fill(0); rect(0,0,640,400); for(int i = 0; i < particula.length; i++){ particula[i].render(); particula[i].actualizar(); particula[i].reboteBordes(); particula[i].updateTexto(); } } class Particula extends Texto{ //-------- VARIABLES PRINCIPALES -----------------------------------------// Vect2 vel; float diam; //------------ CONSTRUCTOR -----------------------------------// Particula(Vect2 [] pos, Vect2 vel){ super(pos); this.vel = vel; diam = 40; } //------------ MÉTODOS -----------------------------------// void render(){ fill(255,100); for(int i = 0; i<pos.length; i++){ ellipse(pos[i].x,pos[i].y,diam,diam); } } //---------------------------------------------------------// void actualizar(){ pos.add(vel); } void updateTexto(){ super.updateTexto(); } //---------------------------------------------------------// //Método para que las pelotas reboten por la pantalla sin salirse fuera void reboteBordes(){ for(int i = 0; i<pos.length; i++){ if(pos[i].x < diam/2){ // Borde vertical izquierdo pos[i].x = diam/2; vel.x *= -0.8; } if(pos[i].x > width-diam/2){ // Borde vertical derecho pos[i].x = width-diam/2; vel.x *= -1.2; } if(pos[i].y < diam/2){ // Borde horizontal superior pos[i].y = diam/2; vel.y *= -0.8; } if(pos[i].y > height-diam/2){ // Borde horizontal inferior pos[i].y = height-diam/2; vel.y *= -1.2; } } } //------------ FIN DE LA CLASE -------------------------// } class Texto{ //------------- VARIABLES PRINCIPALES ------------------------------------// Vect2 [] pos; // Coordenadas de inserción del Texto String[] words = { "INCINERACION", "CREMACIÓN", "CIELO", "INFIERNO", "LIMBO", "ALMA " }; //------------- CONSTRUCTOR ------------------------------------// // Tenemos que meterle al constructor todas estas variables Texto(Vect2 [] pos){ this.pos = pos; } //------------- MÉTODOS ------------------------------------// // Método para actualizar el texto void updateTexto(){ fill(255,0,0); textFont(fuente); textAlign(CENTER,CENTER); for(int i =0; i < pos.length; i++){ for(int j =0; j < words.length; j++){ text(words[j], pos[i].x, pos[i].y); } } } //------------- FIN DE LA CLASE ------------------------------------// }