Rotating text round a hexagon
in
Programming Questions
•
6 months ago
Dear all interested readers,
I'm trying to make a rotating hexagon with text on every corner. The text should be rotated so that it looks like the text are connected to the centre. I'll visualise it in the next picture:
The code I have now draws the text, but I really don't now how to rote the words as shown above. I've been trying RotateZ with push and popmatrix, but this doesn't work out the way it needs.
Hope that someone can help me with this problem. Thanks in advance.
I'm trying to make a rotating hexagon with text on every corner. The text should be rotated so that it looks like the text are connected to the centre. I'll visualise it in the next picture:
The code I have now draws the text, but I really don't now how to rote the words as shown above. I've been trying RotateZ with push and popmatrix, but this doesn't work out the way it needs.
String tekst = "Boston Bomber";
String bronnen = "Source";
int een, twee, drie, vier, vijf, zes;
String input;
import processing.opengl.*;
PFont font;
int hoekje;
int getal = 2;
boolean hoek = false;
PGraphics pg;
void setup() {
size(1300, 800, OPENGL);
fill(100);
pg = createGraphics(width, 100);
font = createFont("Arial", 300);
// noCursor();
textSize(20);
noStroke();
}
void draw() {
background(0);
//lights();
pg.background(0, 0);
pg.beginDraw();
pg.textFont(font, 30);
textFont(font, 30);
float sw = textWidth(tekst);
pg.fill(0, 0, 255);
pg.rect(0, 28, sw+20, 38);
pg.fill(255);
pg.text(tekst, 0, 55);
if (bronnen.indexOf("vk")>=0)
{
bronnen = "volkskrant";
}
pg.text(bronnen, 0, 100);
pg.endDraw();
// image(pg, 0, 0);
pushMatrix();
translate(width/2, height/2);
float a = map(hoekje, 0, height, 0, PI/2);
rotateX(a);
rotateZ(-frameCount/120.0);
// axis();
// pyramid(60);
polygon(6, 0, 0, 350);
text(6, 0, 0, 350);
zijden(6, 0, 0, 350);
if (hoekje <680 && hoek == false) {
hoekje = hoekje+1;
}
else {
hoek = true;
hoekje = hoekje-1;
if (hoekje <680 ) {
hoekje = hoekje+1;
hoek = false;
}
}
popMatrix();
image(pg, 0, 0);
}
void text(int n, float cx, float cy, float r)
{
float angle = 360.0 / n;
stroke(0);
strokeWeight(3);
beginShape();
fill(255);
for (int i2 = 0; i2 < n; i2++)
{
stroke(0, 0, 255);
if (i2 == 0) {
// fill(0,255,0);
line( cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), 0, cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), zes); // z in blue
noStroke();
text("economie", cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), 0);
}
if (i2 == 1) {
line( cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), 0, cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), een); // z in blue
// fill(0,255,0);
noStroke();
pushMatrix();
text("wetenschap", cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2))+10, 0);
popMatrix();
}
if (i2 == 2) {
// fill(0,255,0);
line( cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), 0, cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), twee); // z in blue
noStroke();
text("politiek", cx + r * cos(radians(angle * i2))-100, cy + r * sin(radians(angle * i2))+10, 0);
}
if (i2 == 3) {
// fill(0,255,0);
line( cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), 0, cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), drie); // z in blue
noStroke();
text("sport", cx + r * cos(radians(angle * i2))-100, cy + r * sin(radians(angle * i2))+10, 0);
}
if (i2 == 4) {
// fill(0,255,0);
line( cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), 0, cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), vier); // z in blue
noStroke();
text("conflict", cx + r * cos(radians(angle * i2))-150, cy + r * sin(radians(angle * i2))+10, 0);
}
if (i2 == 5) {
// fill(0,255,0);
line( cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), 0, cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2)), vijf); // z in blue
noStroke();
text("cultuur", cx + r * cos(radians(angle * i2)), cy + r * sin(radians(angle * i2))+10, 0);
}
}
}
//noStroke();
void polygon(int n, float cx, float cy, float r)
{
float angle = 360.0 / n;
stroke(0);
strokeWeight(3);
beginShape();
for (int i = 0; i < n; i++)
{
if (i == 1) {
fill(0, 0, 255, 255);
vertex(cx + r * cos(radians(angle * i)),
cy + r * sin(radians(angle * i)), een);
}
if (i == 2) {
fill(0, 0, 255);
vertex(cx + r * cos(radians(angle * i)),
cy + r * sin(radians(angle * i)), twee);
}
if (i == 3) {
fill(0, 0, 255);
vertex(cx + r * cos(radians(angle * i)),
cy + r * sin(radians(angle * i)), drie);
}
if (i == 4) {
fill(0, 0, 255);
vertex(cx + r * cos(radians(angle * i)),
cy + r * sin(radians(angle * i)), vier);
}
if (i == 5) {
fill(0, 0, 255);
vertex(cx + r * cos(radians(angle * i)),
cy + r * sin(radians(angle * i)), vijf);
}
if (i == 0) {
fill(0, 0, 255);
vertex(cx + r * cos(radians(angle * i)),
cy + r * sin(radians(angle * i)), zes);
}
}
endShape(CLOSE);
//noStroke();
}
void zijden(int n, float cx, float cy, float r)
{
float angle = 360.0 / 6;
stroke(0);
strokeWeight(3);
fill(255);
beginShape();
vertex(cx + r * cos(radians(angle * 1)),
cy + r * sin(radians(angle * 1)), een);
vertex(cx + r * cos(radians(angle * 2)),
cy + r * sin(radians(angle * 2)), twee);
vertex(cx + r * cos(radians(angle * 2)),
cy + r * sin(radians(angle * 2)), 0);
vertex(cx + r * cos(radians(angle * 1)),
cy + r * sin(radians(angle * 1)), 0);
endShape(CLOSE);
beginShape();
vertex(cx + r * cos(radians(angle * 2)),
cy + r * sin(radians(angle * 2)), twee);
vertex(cx + r * cos(radians(angle * 3)),
cy + r * sin(radians(angle * 3)), drie);
vertex(cx + r * cos(radians(angle * 3)),
cy + r * sin(radians(angle * 3)), 0);
vertex(cx + r * cos(radians(angle * 2)),
cy + r * sin(radians(angle * 2)), 0);
endShape(CLOSE);
beginShape();
vertex(cx + r * cos(radians(angle * 3)),
cy + r * sin(radians(angle * 3)), drie);
vertex(cx + r * cos(radians(angle * 4)),
cy + r * sin(radians(angle * 4)), vier);
vertex(cx + r * cos(radians(angle * 4)),
cy + r * sin(radians(angle * 4)), 0);
vertex(cx + r * cos(radians(angle * 3)),
cy + r * sin(radians(angle * 3)), 0);
endShape(CLOSE);
beginShape();
vertex(cx + r * cos(radians(angle * 4)),
cy + r * sin(radians(angle * 4)), vier);
vertex(cx + r * cos(radians(angle * 5)),
cy + r * sin(radians(angle * 5)), vijf);
vertex(cx + r * cos(radians(angle * 5)),
cy + r * sin(radians(angle * 5)), 0);
vertex(cx + r * cos(radians(angle * 4)),
cy + r * sin(radians(angle * 4)), 0);
endShape(CLOSE);
beginShape();
vertex(cx + r * cos(radians(angle * 5)),
cy + r * sin(radians(angle * 5)), vijf);
vertex(cx + r * cos(radians(angle * 6)),
cy + r * sin(radians(angle * 6)), zes);
vertex(cx + r * cos(radians(angle * 6)),
cy + r * sin(radians(angle * 6)), 0);
vertex(cx + r * cos(radians(angle * 5)),
cy + r * sin(radians(angle * 5)), 0);
endShape(CLOSE);
beginShape();
vertex(cx + r * cos(radians(angle * 6)),
cy + r * sin(radians(angle * 6)), zes);
vertex(cx + r * cos(radians(angle * 1)),
cy + r * sin(radians(angle * 1)), een);
vertex(cx + r * cos(radians(angle * 1)),
cy + r * sin(radians(angle * 1)), 0);
vertex(cx + r * cos(radians(angle * 6)),
cy + r * sin(radians(angle * 6)), 0);
endShape(CLOSE);
//noStroke();
}
Hope that someone can help me with this problem. Thanks in advance.
1