# Is there a way of implementing an arithmetic progression with geometry nodes?

I am new to the Geometry Nodes and trying to use them for implementing an arithmetic progression.

I want to mimic the behavior of the following script, but I haven't been able to so far since I cannot figure out how to create for-loop-like geometry nodes (if even possible).

import bpy

rows = 5
increment = 2
x_spacing = 4
y_spacing = 4
size = 2

obj = bpy.context.active_object

for i in range(0, rows):
if i == 0: increment = 1
for j in range(0, i+increment):
new_location = (
obj.location.x + i * x_spacing,
obj.location.y + j * y_spacing - (i-j) * x_spacing,
obj.location.z,
)


I could only come up with a hacky solution, but it is not what I need.

(Both the script and my hacky solution with Geometry Nodes are included in the attached file)

• Reproducing your code in geometry nodes can be done in B4.0 using two nested "repeat zones". Achieving the result you want would require you to elaborate more, as it seems you already achieved it? Keep in mind, the increment will always be 1 in your code. Aug 31 at 23:26

Well, I would say this is a useful solution:

The principle simply relies on Duplicate Elements and Accumulate Field.

First I create a mesh line. This represents the rows.

I accumulate the value for Increment per point, so that I get the values for an arithmetic progression.

With this value I duplicate the points.

Finally, I simply move them according to their Duplicate Index and instantiate the cubes.

(Blender 3.6+)

• you could just use the (index + 1) × amount instead of accumulate field. Sep 8 at 12:32

If I've read you right, to achieve the final effect, (if not the internal logic,) you could just implement some adjusted variation of this: using the sum of X and Y coordinates as a threshold:

If this is what you're after:

# Starting point for node group:

• I'm sure someone else can do a cleaner job of this but I thought I'd offer this starting point for now and hopefully update it tomorrow.

Using simulation node in node group so you must ensure scene frame is equal to or greater than rows.

conceptually you grow one line segment each frame until the frame number is equal to the desired number of rows.

This in turn can be used to instance new lines that are grown along the y-axis as a function of rows-instance index.

re-sampling the instances on the y axis based on their lengths provides the points required to instance your final geometry mesh.

also slight code change below:

import bpy

rows = 5
increment = 1
x_spacing = 4
y_spacing = 4
size = 2

if not bpy.context.active_object: