ArrayList to function error

edited March 2017 in Questions about Code

Hello, I need a little bit of help, can't gen why there is an error in the sketch. I have big arraylist with all the instances, and a little arraylist of some instances, and I'm trying to put little arraylist to function, but inside the function I can't get the class instance variables, the function does'nt see the variables. Why?

ArrayList <Ellipse > all_ellipses = new ArrayList <Ellipse> ();
ArrayList <Ellipse > some_ellipses = new ArrayList <Ellipse> ();


void setup()
{
  size(600,600);
  for(int i =0; i<100; i++)
  {
    Ellipse temp = new Ellipse(random(10,50));
    all_ellipses.add(temp);
  }

  for(int i =0; i<all_ellipses.size(); i++)
  {
    if(all_ellipses.get(i).radius<15)

    some_ellipses.add(all_ellipses.get(i));
  }
}


void fn_Rad(ArrayList some_ellipses)
{
  for(int i =0; i<some_ellipses.size(); i++)
  {
    some_ellipses.get(i).radius += random(-1,1);
  }
}


void draw()
{
  println(some_ellipses.size());
  for (int i = some_ellipses.size ()-1; i >= 0; i--)
  { 
    some_ellipses.get(i).display();
  }

  fn_Rad(some_ellipses);
}


class Ellipse
{
  float radius;
  PVector pos=new PVector();

  Ellipse(float radiusIn)
  {
    radius = radiusIn;
    pos.x=random(width);
    pos.y=random(height);
  }

  void display()
  {
    noFill();
    stroke(0);
    ellipse(pos.x,pos.y,radius,radius);
  }
}
Tagged:

Answers

  • Answer ✓

    void fn_Rad(ArrayList some_ellipses) => void fn_Rad(ArrayList<Ellipse> some_ellipses)

  • Change line 23: void fn_Rad(ArrayList<Ellipse > some_ellipses)

    Kf

  • wow, thanks for a quick and right answer!

Sign In or Register to comment.