Simulate a for loop to create a grid of oval layers

Hi,

I’m trying to copy the for loop paradigm into Vuo by creating a grid of ovals.

for(int x=-1; x<1; x+=0.02){
  for(int y=0.6; x>-0.6; y-=0.01){
     createOval(x,y);
  }
}

The Vuo sketch works by creating a list of 200 ovals. each time the ‘Build List’ index port reaches 100 an event signal is sent from the ‘Select Event Output’ to decriment the y-value by 0.02. But since I’m not sure how to reset the ‘Set Count’ port for the x-axis (sending the same event to this port doesn’t work) I get the wrapped around version in the image below.

What I want is to also reset the x-value to -1 each time 100 ovals are reached so that the oval rows are aligned perfectly vertically.

Can you help?

Thanks

emulating_for_loop.vuo (4.86 KB)

The general concept is that you need two lists, if one list is for your x coordinates, then y coords is a list of the x coord list (your for loop does y coords first, then x). The pic shows an example, Make Points Along Line generates a list, you can use two, one for x range, one for y range.

I know this pic shows a different approach from using Build List, certainly possible with that node, but there are built in tools for grids that solve the issue. Controlling the order grid items generate would be another matter, there’s an exercise that might be worth pursuing.

And of course some good compositions involving grids around the forums here.  

3 Likes

Thanks @jersmi hadn’t thought of sending the output of one copy layer into the other. Thanks for your time again. Much appreciated.  

If you want to animate how the grid generates on screen, left to right, top to bottom, etc. would have to also animate end point on Make Point Along Line. I think that would work… left alone it always fills the range, i.e., generates from center out.

(Mm.points has a grid generator for 2d and 3d points :wink:)

1 Like

Yep! Included in Vuo as Make Points in 2D Grid and Make Points in 3D Grid as of Vuo 2.4.0.