//Declare variables (put at the beginning outside of any command) munequito m1; //nombrando los munequitos como m1 y 2 munequito m2; // Code that runs forever goes here -set up the applet void setup() { size(400,300); // applet size // darle a los munequitos valores diferentes color y tamano m1= new munequito (50,50,10,5,color(50,255,50)); //volver a esto mas tarde m2= new munequito(150,54,5,10,color(50,100,250)); } void draw(){ background(208,128,254); // color framerate(10); m1.draw_munequito(); m1.move_munequito(); m2.draw_munequito(); m2.move_munequito(); } //set up the class for objeto munequito class munequito{ //declare variables for object munequito int horizPosi; int vertiPosi; int horiVeloc; int vertVeloc; color nariz_color; int ancho_cabeza =100; int alto_cabeza =60; int ancho_nariz=90; int alto_nariz=30; int ancho_ojo=10; int alto_ojo=15; int sonrisa_comienzo1=130; int sonrisa_comienzo1a=105; int sonrisa_comienzo2=160; int sonrisa_comienzo2a=105; int right_bnd = 800; int left_bnd = -800; int top_bnd = 550; int bottom_bnd = -550; //instatiate -- initialize munequito variables munequito (int hp, int vp, int hv, int vv, color nc){ horizPosi =hp; //posicionandolo en el lugar inicial horizontal vertiPosi=vp; //posicionandolo en el lugar inicial vertical horiVeloc = hv; vertVeloc = vv; nariz_color = nc; // set boundaries of munequito para que no se salga de la caja right_bnd = width - (ancho_cabeza/2); // set right boundary left_bnd = ancho_cabeza/2; // set left boundary top_bnd = (alto_cabeza/2) + ancho_cabeza - 5; //set top boundary bottom_bnd = height - (alto_nariz/2) - 5; // set bottom boundary } // draw munequito.... void draw_munequito (){ stroke(0,200,100); rectMode(CENTER); //head w-green fill fill(nariz_color);//green fill ellipse(horizPosi,vertiPosi, ancho_cabeza, alto_cabeza);//head ellipse(horizPosi,vertiPosi+20, ancho_nariz, alto_nariz);//snout noFill(); //smile stroke(#AB3603); bezier(horizPosi-40, vertiPosi+20, sonrisa_comienzo1, sonrisa_comienzo1a, sonrisa_comienzo2, sonrisa_comienzo2a, horizPosi+40, vertiPosi+20); noStroke(); //begin eyes with black fill fill(#000000); ellipse(horizPosi-20, vertiPosi-2, alto_ojo, ancho_ojo);//left eye ellipse(horizPosi+20, vertiPosi-2, alto_ojo, ancho_ojo);//right eye noFill(); } // move munequito -- set the horizontal and vertical positions void move_munequito() { horizPosi (); } //move the munequitos // move munequito along x-axis by setting next xpos // if munequito is touching left or right boundary // then reverse direction void horizPosi () { horizPosi += horiVeloc; if (horizPosi > right_bnd) { horizPosi = right_bnd; horiVeloc *= -1; } else if (horizPosi < left_bnd) { horizPosi = left_bnd; horiVeloc *= -1; } } }