Skip to content

Instantly share code, notes, and snippets.

@fartagaintuxedo
Created July 10, 2013 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fartagaintuxedo/5967876 to your computer and use it in GitHub Desktop.
Save fartagaintuxedo/5967876 to your computer and use it in GitHub Desktop.
PrintWriter output;
int numpers=60;
Persona[] listpers=new Persona[numpers];
void setup(){
size(600,400);
smooth();
output=createWriter("lista.csv");
String[] nombresCH={"qing","gao","huang","li","qiong","bruce","lee", "wang", "xu", "sheng","wen", "zhu", "hong"};
String[] nombresES={"alejandra", "fatima", "eugenia", "marta", "ana", "maria", "carmen", "lucia","sandra"};
for(int i=0;i<listpers.length;i++){
PVector loc=new PVector(random(0,width),random(0,height));
PVector vel=new PVector(0,0);
PVector acc=new PVector(0,0);
String nombre=nombresES[int(random(0,nombresES.length))]+" "+nombresCH[int(random(0,nombresCH.length))];
listpers[i]=new Persona(loc,vel,acc,nombre,random(-10,10),random(-10,10),"sexo1",0);
}
}
void draw(){
background(255);
for(int i=0;i<listpers.length;i++){
Persona p=listpers[i];
p.buitre();
p.render();
p.bordes();
}
if(frameCount==10000){
printPuntuacion();
}
println(frameCount);
}
void printPuntuacion(){ //graba en un fichero las puntuaciones de todas las particulas al cabo de un tiempo x
output.println("total;belleza;simpatia;puntuacion");
for(int i=0;i<listpers.length;i++){
Persona p=listpers[i];
output.println(str(p.belleza+p.simpatia)+";"+str(p.belleza)+";"+str(p.simpatia)+";"+str(p.puntuacion));
}
output.flush();
output.close();
}
class Persona {
PVector loc;
PVector vel;
PVector acc;
String nombre;
float belleza;
float simpatia;
String sexo;
float puntuacion;
Persona( PVector _loc, PVector _vel, PVector _acc,
String _nombre, float _belleza, float _simpatia, String _sexo, float _puntuacion){
loc=_loc;
vel=_vel;
acc=_acc;
nombre=_nombre;
belleza=_belleza;
simpatia=_simpatia;
sexo=_sexo;
puntuacion=_puntuacion;
}
void buitre(){ //hace que la persona huya o se acercque a otras en funcion de la puntuacion de estas.
float minDist=70; // distancia umbral de interaccion
float maxDist=30; //distancia minima de confort
for(int i=0;i<listpers.length;i++){
Persona p=listpers[i];
if((p.loc.x-loc.x<minDist && -p.loc.x+loc.x<minDist) && (p.loc.y-loc.y<minDist && -p.loc.y+loc.y<minDist)){
PVector d=PVector.sub(p.loc,loc);
float distancia=d.mag();
d.normalize();
avoid(distancia, d);
d.mult((p.belleza + p.simpatia)/(20*100));
updatePuntuacion(p.belleza,p.simpatia);
if (distancia>maxDist){
acc.add(d);
vel.add(acc);
loc.add(vel);
vel.mult(0);
strokeWeight(0.5);
stroke(0,50);
line(loc.x,loc.y,p.loc.x,p.loc.y);
}
}
}
}
void avoid(float distancia, PVector d){//esta funcion evita que se choquen y superpongan las particulas-personas //d should be normalized
float mindist=30;
if(distancia<mindist && distancia>0){
float coef=(-mindist/(distancia+1));
//coef=constrain(coef,-1,1);
d.mult(coef);
acc.add(d);//estas 3 lineas
vel.add(acc);//producen el movimiento
loc.add(vel);//de las particulas
acc.mult(0.1); // para que no se acumule la aceleracion y se le vaya la olla, es un valor a huevo
}
}
void updateSimpatia(){
//no esta hecha, seria que cuando tengas mucha fama baje tu simpatia
}
void updatePuntuacion(float bell,float simp){
puntuacion=puntuacion+bell+simp; //suma la simpatia y belleza de los vecinos en cada instante.. para ver al final si te has juntado con gente guay o con pringuis
}
void render(){
noStroke();
fill(belleza*10+50,20,20);
ellipse(loc.x,loc.y,28,28);
stroke(255);
fill(20,20,simpatia*10+50);
ellipse(loc.x,loc.y,16,16);
noStroke();
fill(255);
ellipse(loc.x,loc.y,4,4);
}
void bordes(){
if(loc.x>width+20){
loc.x=-20;
}
if(loc.x<-20){
loc.x=width+20;
}
if(loc.y>height+20){
loc.y=-20;
}
if(loc.y<-20){
loc.y=height+20;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment