yves
September 21, 2022, 3:42pm
1
Hi every one,
I’m working on that example of scrolling headlines from : scrollingtext | Learning Processing 2nd Edition
how can I “play” headlines vertically with a line break at the end of each headline
something like :
pushMatrix() ;
pushStyle();
for (int i=0; i<headlines.length; i++) {
text(headlines[i],width/2,100,'\n');
}
popStyle();
popMatrix();
Thank’s for any help
Yves
josephh
September 22, 2022, 7:25am
2
Hi @yves ,
Can you please elaborate on that? Maybe post a sketch of what it would look like.
If I understand correctly you mean displaying multiple headlines vertically and moving from top to bottom? Do they have different speed and timing?
yves
September 24, 2022, 9:00am
3
thank’s for the answer,
I have these headlines :
// An array of news headlines
String[] headlines = {
"Processing downloads break downloading record.",
"New study shows computer programming lowers cholesterol.",
"bla bla bla",
};
I want to make a text with the first and the second headline with a line break between them
something like :
pushMatrix() ;
pushStyle();
for (int i=0; i<headlines.length; i++) {
text(headlines[i],width/2,100,'\n');
}
popStyle();
popMatrix();
thank’s
Yves
mnse
September 24, 2022, 9:45am
4
Hi @yves ,
you can play arround a bit with that, so you can find a way to do …
Cheers
— mnse
String[] lines;
color[] colors;
int lineHeight;
void setup() {
size(600, 400);
textSize(40);
lineHeight=int(textAscent()+textDescent());
int maxLines = height / lineHeight;
lines = new String[maxLines];
colors = new color[maxLines];
colorMode(HSB, maxLines, 100, 100);
for (int i = 0; i < maxLines; i++) {
lines[i] = "I'm line "+(i+1)+" of "+maxLines+" lines...";
colors[i] = color(i, 100, 100);
}
}
void draw() {
background(0);
for (int i = 0, y = lineHeight; i < lines.length; i++, y+=lineHeight) {
int idx = (int(frameCount/25)+i) % lines.length;
fill(colors[idx]);
text(lines[idx], 20, y);
}
}
yves
September 24, 2022, 9:51am
5
mnse:
String[] lines;
color[] colors;
int lineHeight;
void setup() {
size(600, 400);
textSize(40);
lineHeight=int(textAscent()+textDescent());
int maxLines = height / lineHeight;
lines = new String[maxLines];
colors = new color[maxLines];
colorMode(HSB, maxLines, 100, 100);
for (int i = 0; i < maxLines; i++) {
lines[i] = "I'm line "+(i+1)+" of "+maxLines+" lines...";
colors[i] = color(i, 100, 100);
}
}
void draw() {
background(0);
for (int i = 0, y = lineHeight; i < lines.length; i++, y+=lineHeight) {
int idx = (int(frameCount/25)+i) % lines.length;
fill(colors[idx]);
text(lines[idx], 20, y);
}
}
thank’s for the answer,
I’m in P3D mode, it’s not working with this mode,
But, I’ll try something like this
++
Yves
mnse
September 24, 2022, 10:13am
6
Hi @yves ,
The above also works in P3D !? Below only P3D mode enabled …
String[] lines;
color[] colors;
int lineHeight;
void setup() {
size(600, 400, P3D);
textSize(40);
lineHeight=int(textAscent()+textDescent());
int maxLines = height / lineHeight;
lines = new String[maxLines];
colors = new color[maxLines];
colorMode(HSB, maxLines, 100, 100);
for (int i = 0; i < maxLines; i++) {
lines[i] = "I'm line "+(i+1)+" of "+maxLines+" lines...";
colors[i] = color(i, 100, 100);
}
}
void draw() {
background(0);
for (int i = 0, y = lineHeight; i < lines.length; i++, y+=lineHeight) {
int idx = (int(frameCount/25)+i) % lines.length;
fill(colors[idx]);
text(lines[idx], 20., y);
}
}
Cheers
— mnse
1 Like