# GHpython: Generartive spawning circles

Hi,

I’m trying to generate circle spawning from one base circle where a circle is spawned from this base circle and from this circle, another circle is spawned etc until the circles fill up the curve boundary.

The whole process will start off with a for loop in which everything is contained in and the initial steps i have are:

1. for i in count of x (where x is the number of circles we want to generate)
2. generate the first circle and create a list so that the last item on the list is the one chosen to generate the next circle from
3. Every time it spawns it has to check if there is a curve intersect with the outside boundary, if yes they it will need to be rotated

The current script I have at the moment is this:

import rhinoscriptsyntax as rs
from Rhino.Geometry import Circle
from Rhino.Geometry import Point3d
from Rhino.Geometry import Vector3d
import Rhino.Geometry.Transform as rgt
import scriptcontext as sc

firstPoint = rs.coerce3dpoint(startPoint) #create firstPoint variable

a = #create a list for output
count = len(a) #create count for list

for i in range of count:

def spawnCircle(firstPoint, recursion): #define circle spawning function

``````a.append(firstPoint) #adding data to this list

if recursion < 10: #creating a loop within the function
movedPoint1 = firstPoint + Point3d(10, 5, 0) #moving point function within the loop
spawnCircle(movedPoint1, recursion + 1) #creating a cap for the loop
``````

spawnCircle(firstPoint, 0) #spawn the new circles

moveVecX = 6 #define vectorX distance
moveVecY = 20 #define vectorY distance
moveVecZ = 8 #define vectorZ distance

moveVector = rs.CreateVector(moveVecX, moveVecY, moveVecZ) #moving according to the vectors above
xf = rgt.Translation(moveVector) #defining the moving variable

a = sc.doc.Objects.Transform(startPoint,xf,bool) #executing the move function

Not sure how to fix it so any help will be greatly appreciated!!

Check out this tutorial by @jho. I think it could get you started with a potentially better way to do something like you described.

1 Like

Thank you this is very helpful!!

As he uses the populate2d node, is there a simple way to make the point spawning not random but each circle is generated from the last spawned circle?

Yes, that would be feasible.

What do you mean by “they it will need to be rotated”, when circles intersect the boundary curve?

How does the boundary curve look like?

For example if a circle is spawned and it intersects with the boundary curve (can be any shape such as a rectangle), it can maybe rotate on a certain point until it no longer interacts with the boundary curve.

How would I begin to code the circle generation from the last spawned circle within python? Not sure how to start that

Are you sure you want to do this in Python? I can help you, but I wanna make sure before we go down that rabbit hole.

You can also do it with Kanagaroo.

Or you could find the closest point from the intersecting circle center on the boundary curve and thus the vector between both and use it move the circle in the opposite direction or even direction of the reflex vector?

Basically, you need to control the recomputation of the GHPython component itself. It can be done with Python or by attaching a trigger component to the GHPython one.
You also need to make sure that your data sticks when the component recomputes. That can be done with a sticky dictionary or global variables.
You need to recompute the component to make it animated.

After that it’s just a matter of generating a new circle at each iteration/recomputation, relax everything, and store the current state, before advancing an iteration.

1 Like