## Jittery Rectangles – Example 1.3

This third example uses the concept of movement to move an initial group of same sized rectangles in a random x and/or y direction.

**Step One – Setup a grid of points.**

This time, rather than using one of the standard grids, I’m going to create my own “custom” grid of points from scratch, by constructing points based on two series of numbers. This could have some uses, but it is mostly just to show a bit more how data is structured, as well as to look again at the series component.

In the top script, I have two series of numbers, one list with 6 numbers, and one with 4. If I put these two series into the “Construct Point” component, for the X and Y values, you’ll see that it takes Item 0 from the first list, and matches it with Item 0 from the second list, draws a point, and then moves onto Item 1/1, 2/2, and so on. For the 5th point, It takes Item 4 from the first list, but the second list ran out of items! So what does it do. In this case it just reuses or recycles the last item in the list. So Items 3, 4, and 5 from list one are all matched with Item 3 from list 2.

In the bottom script I made a small change. I grafted the numbers coming out of the Series. This puts each number in its own little precious container. When these two lists (which are structured differently, are matched together, something odd happens. In the first example I told you that you should generally avoid matching differently structured lists…now, so early in the game, I am breaking my own advice. What happens, though, which is something we want in this case, is the first branch of the grafted list is matched with EACH item in the “normal” list. The same goes for the other branches. In the resulting points produced by “Construct Point” you can see that a new data structure is created with as many branches as there were in the second series. So now we have a grid!

Notice this works only if you graft one series of numbers into the X OR Y coordinate (but not both). By deciding which of the X or Y series of numbers you graft, you can decide whether your “Lists” in the normal data structure are in columns or rows. You could set this up with a grid of points like the first example as well, but you would then need to flip the grid matrix if you wanted to randomly affect rows vs. columns. Anyways, enough of that. And thanks for your patience!

**Step Two** **– Draw starting rectangles**

Now to draw the rectangles. Notice rectangles are a bit complicated to draw (Not as easy as the Polygons or circles from before!). You will need a “Domain” component to set both the length and the width.If you want to draw your rectangles centered on your points, you will need to have an equal Positive and Negative value on your domains. So you have to do a bit of math here. If you want rectangles that are 2 units wide, the domain should be -1 to +1. To get this setup in the domain you would divide your TOTAL width by 2, and put the positive value into the “A” port of your domain and then use the “Negative” component to put the negative of this into the “B” port of your domain.

Notice I simplified it a bit in the “Y” direction. Actually you would probably only want to use one of the two methods shown. If you are doing simple math, you can use the standard math operators, but anything more complex (and sometimes even for simple formulas), I prefer to use the “Expression” component. Also, you can also type a formula directly into the “B” input port. In this case, I right clicked on the B and set an expression that b would be equal to “-x” The star by the B lets you know a formula has been put in. I prefer not to use these since you can’t tell whats going on if you see a screenshot, but you can do this if you’d like

**Step Three – Move rectangles randomly in X direction**

We are now going to do two sets of “Move” operations. For the movement of the rectangles I am going to use a random number generator like last time. Every time you use the move component, though, notice you need to first plug the random number (or any number) into an “X Direction” vector component. Otherwise it won’t know what direction you want to move it in. A common starting mistake is to not specify the direction on the Move component. You think to yourself “I want to move it 2” so you put in two, but the computer NEEDS to know a direction as well. There are 3 basic direction components, Vector X, Vector Y, and Vector Z, but later we will look at also moving items in more complex vectors.

Since the random number generator is here generating both positive and negative values, the rectangles can move left or right. I have the original positions show here dashed for reference, but you will not see these rectangles if you turn OFF the preview on the geometry from the previous steps.

**Step Four** – **Move rectangles randomly in Y direction**

After we move in the X, we are going to do the exact same operation in the “Y” direction. I just copied and pasted the previous procedure, and changed the Random Seed so the “Y” movements would not be the same as the “X” movements.

**Step Five – Color the Geometry**

**Playing with the Data Structure**

You might want to go back to the start now and play with the data structure. Notice if you “Graft” the X points instead of the “Y” points it will changed the way the movements are applied.

If you want a total random movement for each point, you should “Flatten” your points right after the “Construct Point” component.

**Variations**

So now that everything is working fine, you can expand the size of your pattern.

You can also play with the sizes of your rectangles.

Other things you can do are play with the amount of X and/or Y movement, the random number seed, or the data structure. Below are a few variations to try out!

OK, hopefully makes sense. Here is an overall JPG of the script…

**Click Here to Download GH File**

Very nice example indeed.

If you will permit me to say, that in this post you must add a sentence to tell the reader that the aim of this exercise is to create an algorithm that gives the user a “better control of the randomness of the transition of the rectangles”

And I think that this pic must be made clearer.

PS: I have already made the pic, how can I send it to you ?

LikeLike