Cedric wrote on May 15th, 2009, 10:10am:Do you use the penner easing library cause if you do, the example provide pretty much what you want.
http://jesusgollonet.com/processing/pennerEasing/
hello , yes im using that library, but doesnt example doesnt work to me, in my sketch my elements move random and what i need is when my elements go out the boundaries of my sketch they appear in the other side, so they really dont go out of the boundaries. please check the code:
Code:
import penner.easing.*;
cuadrado[] matriz_cuadrados = new cuadrado[35];
int numeros_agentes = 35;
//int time= 0;
float beginning= 0;
float change_x = 90;
float change_y = 90;
float duration = 40;
float x;
float y;
float x_begining;
float y_begining;
cuadrado cua ;
void setup() {
size(800,500);
frameRate(30);
smooth();
background(255, 255, 255);
for (int i = 0 ; i< numeros_agentes ; i++ ){
matriz_cuadrados[i] = new cuadrado(random(200), 90, random(200), 90 , 40 , i );
}
}
void draw() {
background(255, 255, 255);
fill(140,255,100);
for (int i = 0 ; i< numeros_agentes; i++ ){
matriz_cuadrados[i].checkea_tiempo();
matriz_cuadrados[i].dibuja();
matriz_cuadrados[i].checkea_bordes();
matriz_cuadrados[i].checkea_colision();
matriz_cuadrados[i].checkea_tiempo_aumenta();
}
}
void mousePressed() {
for (int i = 0 ; i< numeros_agentes ; i++ ){
// matriz_cuadrados[i].dibuja();
matriz_cuadrados[i].x_begining = matriz_cuadrados[i].x;
matriz_cuadrados[i].y_begining = matriz_cuadrados[i].y;
matriz_cuadrados[i].time = 0;
//time = 0;
matriz_cuadrados[i].change_x = random(600 )-300;
matriz_cuadrados[i].change_y = random(600 )-300;
}
}
class cuadrado {
float x_begining;
float change_x;
float y_begining;
float change_y;
float duration;
float x;
float y;
float time = 0;
int rank;
float radius = 15.0;
float randomfreq= random(850);
float tiempol;
float cambia_volumen = 0.5;
float cambia_bordes_x = 0;
float cambia_bordes_y = 0;
cuadrado (float x_b , float c_x , float y_b , float c_y , float d , int i ) {
rank = i;
x_begining = x_b ;
change_x = c_x;
y_begining = y_b;
change_y = c_y;
duration = d;
}
void dibuja( ) {
fill(0,250,0);
x = Quart.easeOut (time, x_begining , change_x, duration);
y = Quart.easeOut (time, y_begining , change_y, duration);
tiempol = Quart.easeOut (time, 0 , 0.14, duration);
rect(x + cambia_bordes_x , y + cambia_bordes_y ,radius ,radius);
}
void checkea_colision (){
for (int i=0; i<numeros_agentes; i++){
if ( i != rank){
//arreglo[i].synth.set("freq", x );
float dista = dist(matriz_cuadrados[i].x, matriz_cuadrados[i].y, x, y);
if (dista < 22){
// matriz_cuadrados[i].time = 0;
time = 0;
x_begining = x;
y_begining = x ;
change_x = random(190 )-80;
change_y = random(190 )-80;
//duration
}
}
}}
void checkea_bordes (){
if ( y > height + radius){
//arreglo[i].synth.set("freq", x );
cambia_bordes_x = x- radius;
cambia_bordes_y = y - radius;
}
}
void checkea_tiempo_aumenta (){
if (time < duration){
time++;
//x_begining = x;
}
}
void checkea_tiempo (){
if (time == duration){
// print (" " + time);
// time++;
cambia_volumen = 0.0;
//x_begining = x;
}
else {
cambia_volumen = 0.5;
}
}
}