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 › How to add items in arrayList? (newbie)
Page Index Toggle Pages: 1
How to add items in arrayList?? (newbie) (Read 1077 times)
How to add items in arrayList?? (newbie)
Nov 28th, 2009, 12:04am
 
Hello;
I was wondering how to add items in arrayList.
Somthing like this..

class blabla {
 ArrayList blabla;
 PVector o0 =new  PVector(60,150);
 PVector o1 =  new  PVector(120,140);
 PVector o2 =  new  PVector(100,50);
 PVector o3 = new   PVector(180,200);
 PVector o4 = new   PVector(250,150);
 PVector o5 = new   PVector(160,250);
PVector[] graphics = { o0,o1,o2,o3,o4,o5 };
}

Let's say, I have 6 objects in arrayList that hold the position for display some graphic. I want to add some more object to the list. So, I can display more graphic. Something like, when mouseClicked add Pvector(random(width),random(height)) into the list.
I'm not sure that my question is clear because I'm new to processing. Shocked

This is what I'm trying to do.
I want to add ellipse in random position When I clicked mouse.
Can someone help me?? (below is a link to code)
pasteit4me.com/77001

Thanks!!
Re: How to add items in arrayList?? (newbie)
Reply #1 - Nov 28th, 2009, 2:01am
 
It's easy, have a look at the reference :
http://processing.org/reference/ArrayList.html

Code:
ArrayList blabla;
blabla = new ArrayList();
blabla.add(Pvector(random(width),random(height));
for (int i = 0; i < blabla.size(); i++) {
 PVector p = (PVector) blabla.get(i);
 ellipse(p.x, p.y, 10, 10);
}
Page Index Toggle Pages: 1