Random triangles on a grid

Hey,

My knowledge of processing is very poor, so I hope you can help me out. For a school project I want to randomly generate triangles on a grid. The triangles have to be created randomly each time, and in a random place on the grid.

I want the triangles to be constructed out of 1 vertical or horizontal part and 2 sides of 45 degrees, so that the size of the triangles are also random each time.

Here is my code so far of the grid:

    void setup() {
      size(300, 500);
      background(255);
      noStroke();
      smooth();

       for (int i = (width/8); i <= (width*0.875); i = i+30) {
        for (int j = (height/8); j <= (height*0.875); j = j+30) {
          fill(0);
          ellipse(i, j, 2.5, 2.5);
        }
      }
    }

I'm not sure about how to create the triangles though...

Can anyone help me out?

Thanks,

Janneke Kors (NL)

Answers

  • The way I see it, there are four possible orientations for the triangle (one per possible axis alignment), a random size, and then a random location. You should start by picking random numbers for each variable and then you should try to draw the triangle based on those numbers. You can come back if you need help, but at least try to implement what I suggested.

  • Thanks for the answer! Today the deadline for the project become clear and I do not think I'm able to finnish this within time.

    So I give it a break, but really want to continue this in the future.

Sign In or Register to comment.