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 › What does this script do
Page Index Toggle Pages: 1
What does this script do? (Read 666 times)
What does this script do?
May 9th, 2010, 12:25pm
 
ArrayList AntList;
myAnt B;
int maxAnts = 100;


void setup()
   {
     size(400,400);
     stroke(255);
     AntList = new ArrayList();
     
     
     for (int i = 0;i < maxAnts; i++)
         
         AntList.add (new myAnt (random(0,width), random(0,height) ));    }
 
 
      void draw()
   {
     background(0);
     for (int i = 0; i < AntList. size(); i++)
      {
        B = (myAnt) AntList.get(i);

        B.Animate();
      }
   }
   
     class myAnt
   {
     PVector pos;
     myAnt (float x,float y){pos=new PVector(x,y);
   }
   
     void Draw()
   {
     point(pos.x,pos.y);    }
 }
Re: What does this script do?
Reply #1 - May 9th, 2010, 1:06pm
 
This sketch seems to draw 100 random ants on the screen and animate them. Animate is missing though.
But what might be new to you is the Arraylist.

Find out more about arrayLists here: http://processing.org/reference/ArrayList.html

one of the differences is that an arraylist can be resized dynamically. This can be really useful if you dont know the amount of ants you are going to create. But it is slower than an array.
As your number of ants is stored in maxAnts already , an array would be probably the better choise.

You can read more about the difference of Arrays and Arraylists here : http://processing.org/discourse/yabb2/num_1230887778.html
Page Index Toggle Pages: 1