C# _ new class instance_Animation

I am trying to fill the rectangular area with random circles which are growing from certain radius till the boundary of the rectangular area. I have made class initiated in custom code region. Custom class basically is a simple Circle which has functionality of showing and growing.

I am able to animate the circle growing till the edges of the rectangular area. What I’m trying to do is, that to have multiple circles growing from random location till they touch the boundary of rectangular area.

I have random function in class constructor. When I initiate the class it always give me one random value and circle grows from there. I am expecting a random values every time it recomputes. so that new circle will be added to the respected location

Any help would be great!

ps. Attached video link (I am following a tutorial made for processing)

attached gh_file!

    double width = 100; double height = 75;
    Rectangle3d boundary = new Rectangle3d(Plane.WorldXY, width, height);

    List<CPack> circles = new List<CPack>();
    foreach(CPack c in circles)

      if(reset == true)
          c.Growing = false;
        B = c.Show();
        C = c.X;
    A = boundary;


  // <Custom additional code> 
  CPack cP = new CPack(100, 75);

  public class CPack
    public double X;
    public double Y;
    public int Width;
    public int Height;
    public double Radius;
    public bool Growing = true;

    public CPack(int width, int height)
      Random rnd = new Random();
      Width = width;
      Height = height;
      X = rnd.Next(0, width);
      Y = rnd.Next(0, height);
      Radius = 1;
    public Circle Show()
      return new Circle(new Point3d(X, Y, 0), Radius);
    public void Grow()
        Radius = Radius + 0.1;
    public bool edges()
      return (X + Radius > Width || X - Radius < 0 || Y + Radius > Height || Y - Radius < 0);

04_CirclePacking Algorithm.gh (5.6 KB)

This way the seed for the Random engine will be taken from the processor clock time, yielding different random sequences each time (except when you create two Random instances really close together in time, in which case they may end up with the same seed).

To get repeatable randomness, you must specify a constant seed.

Did I understand the problem you were having?

No I didnt want repeatable randomness. I think I failed to express it properly since I myself was confused that time… here is what I was trying to do, its done for now!


1 Like

Hi i was trying something similar, by any chance could you share your final code.


@Alca here it is. I found a script made 2 years ago :grinning:. Hope it helps.CirclePacking Algorithm.gh (6.9 KB)