Hi there! I am trying to do a design using random vertex, as you can see on the picture. I want to take a random point between X1 and X2, that is easy to do, but I don’t know what to do with y, because it has to be on that line. Can you please help me?
void setup() {
size(1000, 1000);
noStroke ();
background(255,255,255);
//central polygon
float x1 = random(100,300);
float y1 = random(100,300);
float x2 = random(300,700);
float y2 = random(100,300);
float x3 = random(700,900);
float y3 = random(100,300);
float x4 = random(700,900);
float y4 = random(300,700);
float x5 = random(700,900);
float y5 = random(700,900);
float x6 = random(300,700);
float y6 = random(700,900);
float x7 = random(100,300);
float y7 = random(700,900);
float x8 = random(100,300);
float y8 = random(300,700);
//sub polygon
float x10 = random(x1,x4);
float y10 = random(y1,y4);
float x11 = random(x6,x7);
float y11 = random(y7,y7);
//red
fill(255,0,0);
beginShape();
vertex(x1,y1);
vertex(x2,y2);
vertex(x3,y3);
vertex(x4,y4);
vertex(x5,y5);
vertex(x6,y6);
vertex(x7,y7);
vertex(x8,y8);
endShape();
//yellow
fill(0,255,255);
beginShape();
vertex(x4,y4);
vertex(x5,y5);
vertex(x6,y6);
vertex(x7,y7);
vertex(x8,y8);
endShape();
//dark blue
fill(255,255,0);
beginShape();
vertex(x2,y2);
vertex(x3,y3);
vertex(x4,y4);
vertex(x5,y5);
vertex(x6,y6);
endShape();
//blue
fill(0,0,255);
beginShape();
vertex(x4,y4);
vertex(x5,y5);
vertex(x6,y6);
endShape();
}