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 & HelpPrograms › making a crowd
Page Index Toggle Pages: 1
making a crowd (Read 361 times)
making a crowd
Feb 20th, 2008, 9:44pm
 
so, i'm very, very new with processing and i need some pointers on a project i'm doing for class.  

my goal is to make a crowd using the same 8 images of figures over and over on a set Y coordinate with randomized Y and Z values.  I'm wanting the lesser Z values to be behind the greater ones so that the smaller figures are not overlapping the larger.

any help here?

and also...to add an element of time, I would potentially like to make the randomized figures advance forward and continue appearing randomly

int[] personX;
int[] personZ;

PImage[] images;

void setup()
{
 size(720, 480, P3D);
 images=new PImage[8];
 images[0]=loadImage("walker.1.pdf");
 images[1]=loadImage("walker.2.pdf");
 images[2]=loadImage("walker.3.pdf");
 images[3]=loadImage("walker.4.pdf");
 images[4]=loadImage("walker.5.pdf");
 images[5]=loadImage("walker.6.pdf");
 images[6]=loadImage("walker.7.pdf");
 images[7]=loadImage("walker.8.pdf");
 //load all images

 personX=new int[50]; //50 people
 personZ=new int[50];
 for(int i=0; i<50; i++)
 {
   personX[i]=int (random(720));
   personZ[i]=int (random(0));
 }
}

void draw()
{
 background(0);
 for(int i=0;i<50;i++)
 {
   pushMatrix();
   translate(personX[i],0,personZ[i]);
   image(images[i%8],0,0);
   popMatrix();
 }
}
Re: making a crowd
Reply #1 - Feb 21st, 2008, 12:01pm
 
you've asked this, or something similar before.

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=LibraryProblems;action=display;num=1202791488

are we doing your homework? will we get credit? 8)

what you want is a very simple particle system. make the people a class of their own with x and z co-ords and an index to the picture you're using.

with each tick increment the z of each person, moving them closer.

clear screen, draw them all starting from the back to the front (sort on z, draw smallest first) (http://en.wikipedia.org/wiki/Painter's_algorithm)

if they reach the front of the screen then set z to the back of the screen.

repeat to fade...

particle system, much more complex than you need:
http://processing.org/learning/examples/simpleparticlesystem.html
Page Index Toggle Pages: 1