aggregating polygons at their edges
in
Programming Questions
•
5 months ago
Hi!
For my project, I need to make different polygons to join at their edges and probably, using GA, fill a given space.
Being new to processing, my coding skills are very slow. For now I have managed to come up to the following:
- void setup()
- {
- size(500, 500);
- background(0);
- //triangle
- fill(255);
- polygon(3, 50, 75, 35, 75, -PI/2);
- //rect
- fill(255,0,0);
- polygon(4, (width-75), 100, 75, 50, PI/4);
- //pentagon
- fill(255, 204, 255);
- polygon(5, 150, 200,55, 75, -PI/20);
- //hexagon
- fill(0, 255, 255);
- polygon(6, 80, (height-80), 75, 75, -PI);
- //octagon
- fill(0, 0, 255);
- polygon(8, (width-150), (height-150), 75, 50, 0);
- }
- void polygon(int n, float px, float py, float w, float h, float startAngle)
- {
- float angle = TWO_PI/ n;
- beginShape();
- for (int i = 0; i < n; i++)
- {
- vertex(px + w * cos(startAngle + angle * i),
- py + h * sin(startAngle + angle * i));
- }
- endShape(CLOSE);
- }
After this, how do incorporate "if the edge length of 2 polygons = a, then join them at that edge. If suppose if each polygon drawn has one of their edge lengths = a, it doesn't matter which polygon joins with which. The choice can be random."...
Also, it is to be noted that that this code doesn't define the polygons with respect to their edge length.
1