Drawing random lines between a grid of ellipses.
in
Programming Questions
•
2 years ago
I have created a grid of ellipses, and I would like to draw lines between the centers of these ellipses. However, I want to randomise where each line begins and where each line ends--all beginning points and ending points being the centers of ellipses.
Below is the code I have used to create the grid of ellipses.
I have tried including the line drawing code within the nested for statements, but I can't seem to figure out how to restrict the lines' points to the ellipses' origins. I have a feeling I might need to use a two-dimensional array to accomplish this, but I am not quite sure how to go about setting up said array.
Also, it appears that my method of centering the grid within the screen isn't accurate. What would be a more accurate and efficient way of accomplishing this?
Any other improvements upon what I have so far would be greatly appreciated. Thank you!
- void setup() {
- size(300, 500);
- background(100);
- 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(255);
- ellipse(i, j, 2.5, 2.5);
- fill(255, 30);
- ellipse(i, j, 20, 20);
- }
- }
- }
1