Processing Month, Day 28 - Distorted Grids

Posted by Jan Vantomme on 28 May 2011.
Tags:

Today, we’re going to distort the grid we made yesterday. To do this, we’ll need to modify the algorithm a little bit. We need a multidimensional PVector array to keep track of the points in the grid. We’ll calculate the normal points and use random() to move them away from the grid. The code below shows you how to fill the array.

for (int j 011j++) {
    
for (int i 011i++) {
         vertices[i][j] 
= new PVectori*40 random(-1010),
                                       
j*40 random(-1010) );
    
}

the code for drawing the grid is a little different too. We don’t calculate the points while drawing in this example, we get them out of the PVector array we’ve set up earlier.

for (int j 010++) {
    beginShape
(QUAD_STRIP);
    for (
int i 011i++) {
        vertex
vertices[i][j].xvertices[i][j].);
        
vertexvertices[i][j+1].xvertices[i][j+1].);
    
}
    endShape
();

Examples

If we draw the grids with QUAD_STRIP and TRIANGLE_STRIP, they’ll look like this.

A distorted quad strip grid.

A distorted triangle strip grid.

Download

Download the examples to create your own distorted grid.

Tweet this article