We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › boundaries of sketch
Page Index Toggle Pages: 1
boundaries of sketch (Read 518 times)
boundaries of sketch
May 15th, 2009, 10:06am
 
Hello how can i make that my elements of my sketch doesnt go out of the boundaries of my sketch? Im animating randomly elements on my sketch and i would like that when they go out the boundaries they appear in the other side of the sketch , any idea of making this?

im using easing functions for animating like this:

  x = Quart.easeOut (time, x_begining , change_x, duration);
  y = Quart.easeOut (time, y_begining , change_y, duration);
    rect(x , y  ,radius ,radius);


thanks



pun.
Re: boundaries of sketch
Reply #1 - 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/

Re: boundaries of sketch
Reply #2 - May 15th, 2009, 10:36am
 
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;
}

}

}



Page Index Toggle Pages: 1