Help to understand and finish my code: GRID with point and random functions, "for" (loop) and space.

Goodmorning everybody, I was trying to use the random() function to create a visually interesting grid ( a number of crossing horizontal and vertical lines) made up of adjacent points (with space between each other) and not by using the line() function. I was trying to use only the loop "for" but I am having problems on the next step. This is the start of my code.

int verticalNumberLines=20; int horizontalNumberLines=20; int space=5; size(400, 400); background(#99ff66); strokeWeight(2); for (int i=0; i<width; i+=width/verticalNumberLines) { for (int j=0; j<height; j+=space) { point(i, j); } } for (int j=0; j<height; j+=height/horizontalNumberLines) { for (int i=0; i<width; i+=space) { point(i, j); } }

this is what I have now

grid 15

and this second gray and orange grid is what I am trying to do, now I am very close and I tried in different ways but I don't understand what I should change, where I should use the random function.Could someone help me, please?!

16809802_10211470424377501_1726481167_n

Answers

  • edited February 2017

    You can add a small offset to the points you are drawing

    This offset could be vertical to the main direction of the line (horiz or vert) and be random(-5,5)

  • Answer ✓

    point(i+random(-6,6), j);

  • Thank you a lot! It's a lot important for me. It's not exactly the same but at least I have an answer. I am feeling better.

  • edited February 2017 Answer ✓

    I think one time, you need to add +random(-3, 3) to the x-, one time to the y-value...

Sign In or Register to comment.