HI,
I’m looking for ideas on how to approach this concept. I have a smaller octagon inside of another ocagon. They are connected by lines on each vertex.
I want to rotate the outside octagon while keeping the inner, smaller one stationary, but I want the lines that connect them to stay connected and stretch while one of them is rotating.
I tried using pushMatrix() and popMatrix() but if I do that the lines disconnect.
If you look at the code I posted you can change r1 or r2 and see what I’m talking about, the connecting lines are disconnecting.
If anyone has any ideas on how to approach this let me know.
Can I rotate just a vertex around a point? Maybe I can group several vertices together and rotate them.
Thank you in advance.
import oscP5.*;
//OSC receive
OscP5 oscP5;
float cx = 0;
float cy = 0;
float radius = 221;
float cx2 = 0;
float cy2 = 0;
float radius2 = 166;
float r1 = 0;
float r2 = 0;
void setup() {
size(800, 800);
oscP5 = new OscP5(this, 12000);
background(255);
}
void oscEvent(OscMessage theOscMessage) {
float value = theOscMessage.get(0).floatValue();
if (theOscMessage.checkAddrPattern("/cx")) {
if (value > -400) {
cx = value;
} else {
cx = 0.0;
}
}
float value2 = theOscMessage.get(0).floatValue();
if (theOscMessage.checkAddrPattern("/cy")) {
if (value2 > -400) {
cy = value2;
} else {
cy = 0.0;
}
}
float value3 = theOscMessage.get(0).floatValue();
if (theOscMessage.checkAddrPattern("/radius")) {
if (value3 > -400) {
radius = value3;
} else {
radius = 0.0;
}
}
float value4 = theOscMessage.get(0).floatValue();
if (theOscMessage.checkAddrPattern("/radius2")) {
if (value4 > -400) {
radius2 = value4;
} else {
radius2 = 0.0;
}
}
float value5 = theOscMessage.get(0).floatValue();
if (theOscMessage.checkAddrPattern("/r1")) {
if (value5 > -400) {
r1 = value5;
} else {
r1 = 0.0;
}
}
float value6 = theOscMessage.get(0).floatValue();
if (theOscMessage.checkAddrPattern("/r2")) {
if (value6 > -400) {
r2 = value6;
} else {
r2 = 0.0;
}
}
float value7 = theOscMessage.get(0).floatValue();
if (theOscMessage.checkAddrPattern("/cx2")) {
if (value7 > -400) {
cx2 = value7;
} else {
cx2 = 0.0;
}
}
float value8 = theOscMessage.get(0).floatValue();
if (theOscMessage.checkAddrPattern("/cy2")) {
if (value8 > -400) {
cy2 = value8;
} else {
cy2 = 0.0;
}
}
}
void draw() {
// background(255);
fill(255, 20);
noStroke();
rect(0, 0, width, height);
// pushMatrix();
// translate(width/2, height/2);
// rightside uptriangles
// upside down trianges
stroke(0);
strokeWeight(3);
//bigger octagon
pushMatrix();
translate(width/2, height/2);
rotate(r1);
beginShape();
//horizontan face
vertex(cx-radius/2, cy-radius);
vertex( cx+radius/2, cy-radius);
//vertical right face
vertex( cx+radius, cy-radius/2);
vertex(cx+radius, cy+radius/2);
// bottome face
vertex( cx+radius/2, cy+radius);
vertex(cx-radius/2, cy+radius);
// left vertical face
vertex( cx-radius, cy+radius/2);
vertex(cx-radius, cy-radius/2);
endShape(CLOSE);
line( cx-radius/2, cy-radius, cx2-radius2/2, cy2-radius2);
line( cx+radius/2, cy-radius, cx2+radius2/2, cy2-radius2);
line( cx+radius, cy-radius/2, cx2+radius2, cy2-radius2/2);
line(cx+radius, cy+radius/2, cx2+radius2, cy2+radius2/2);
line( cx+radius/2, cy+radius, cx2+radius2/2, cy2+radius2);
line(cx-radius/2, cy+radius, cx2-radius2/2, cy2+radius2);
line( cx-radius, cy+radius/2, cx2-radius2, cy2+radius2/2);
line(cx-radius, cy-radius/2, cx2-radius2, cy2-radius2/2);
rotate(r2);
beginShape();
//horizontan face
vertex(cx2-radius2/2, cy2-radius2);
vertex( cx2+radius2/2, cy2-radius2);
//vertical right face
vertex( cx2+radius2, cy2-radius2/2);
vertex(cx2+radius2, cy2+radius2/2);
// bottome face
vertex( cx2+radius2/2, cy2+radius2);
vertex(cx2-radius2/2, cy2+radius2);
// left vertical face
vertex( cx2-radius2, cy2+radius2/2);
vertex(cx2-radius2, cy2-radius2/2);
endShape(CLOSE);
//third inner octagon
beginShape();
vertex(cx2, cy2-radius2);
vertex(cx2+radius2-radius2/4, cy2-radius2+radius2/4);
vertex(cx2 + radius2, cy2);
vertex(cx2+radius2-radius2/4, cy2+radius2-radius2/4);
vertex(cx2, cy2+radius2);
vertex(cx2-radius2+radius2/4, cy2+radius2-radius2/4);
vertex(cx2 - radius2, cy2);
vertex(cx2-radius2+radius2/4, cy2-radius2+radius2/4);
endShape(CLOSE);
// inner square
beginShape();
// vertex(cx2, cy2-radius2);
vertex(cx2+radius2-radius2/4, cy2-radius2+radius2/4);
// vertex(cx2 + radius2, cy2);
vertex(cx2+radius2-radius2/4, cy2+radius2-radius2/4);
// vertex(cx2, cy2+radius2);
vertex(cx2-radius2+radius2/4, cy2+radius2-radius2/4);
// vertex(cx2 - radius2, cy2);
vertex(cx2-radius2+radius2/4, cy2-radius2+radius2/4);
endShape(CLOSE);
// 2nd inner square
beginShape();
vertex(cx2, cy2-radius2);
// vertex(cx2+radius2-radius2/4, cy2-radius2+radius2/4);
vertex(cx2 + radius2, cy2);
// vertex(cx2+radius2-radius2/4, cy2+radius2-radius2/4);
vertex(cx2, cy2+radius2);
// vertex(cx2-radius2+radius2/4, cy2+radius2-radius2/4);
vertex(cx2 - radius2, cy2);
// vertex(cx2-radius2+radius2/4, cy2-radius2+radius2/4);
endShape(CLOSE);
popMatrix();
}