geomerative text and return
in
Contributed Library Questions
•
1 year ago
geomerative does not support a return, if i use \n then i just get a rectangle character.
I have a exhebition with my class next week and we all still really have a lot to do, to much!
I have a script that load subtitles and makes a ArrayList of PVectors to display.
I would like to have the text pretty large in the screen with returns supported. So a lot of text will be smaller then just a few words.
Does someone has any ideas of a good way to do this in geomerative?
(The convertion from geomerative to a PVector array for coordinates of the points is important.)
subtitles script:
- import geomerative.*;
- //
- ArrayList<PVector> targetEdgeVectors;
- //
- ArrayList<Jury> jurys = new ArrayList<Jury>();
- int time = 1421420; // 24*60*1000; // start in ms
- int currentSpeaker = -1;
- String currentSentence;
- int timeLeft;
- void setup() {
- size(1440, 1080, P2D);
- frameRate(25);
- RG.init(this);
- for (int i = 1; i <= 12; i++) {
- jurys.add(new Jury(i));
- }
- loadData("doeke_edit.csv");
- // fast forward
- for (Jury j : jurys) {
- Sentence s = j.sentences.get(j.playIndex);
- while (s.endTime < time) {
- s = j.sentences.get(j.playIndex++);
- }
- }
- smooth();
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void draw() {
- updateSubs();
- background(0);
- text(time, 20, 20);
- if (currentSpeaker != -1) {
- text("jury: "+currentSpeaker+" \n"+currentSentence+"\n"+timeLeft, 20, 50);
- }
- if (targetEdgeVectors != null) {
- fill(255, 0, 0);
- noStroke();
- for (PVector p : targetEdgeVectors) {
- ellipse(p.x, p.y, 5, 5);
- }
- }
- //saveFrame((time/25)+".png");
- time += 40; // dit moet de laatste regel zijn in je draw!
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void createSentence(String s, int polygonizerLength) {
- targetEdgeVectors = new ArrayList<PVector>();
- RShape grp = RG.getText(s, "FreeSans.ttf", 72, LEFT);
- RG.setPolygonizer(RG.UNIFORMLENGTH);
- RG.setPolygonizerLength(polygonizerLength);
- RPoint[] points = grp.getPoints();
- for (int i=0; i<points.length; i++) {
- targetEdgeVectors.add(new PVector(points[i].x + 150, points[i].y + 400));
- }
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void triggerSub() {
- createSentence(currentSentence, 4);
- if (currentSpeaker == 12) {
- // do something
- }
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void triggerSubKill() {
- targetEdgeVectors = null;
- if (currentSpeaker == 12) {
- // do something
- }
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void updateSubs() {
- for (Jury j : jurys) {
- Sentence s = j.sentences.get(j.playIndex);
- if (s.startTime <= time) {
- if (s.triggered == false) {
- println(s.sentence);
- currentSentence = s.sentence;
- currentSpeaker = j.id;
- s.triggered = true;
- triggerSub();
- }
- timeLeft = s.endTime - time;
- if (s.endTime <= time) {
- triggerSubKill();
- j.playIndex++;
- currentSentence = "";
- currentSpeaker = -1;
- }
- }
- }
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- void loadData(String fileName) {
- int START_MILLIS = 2;
- int END_MILLIS = 3;
- int SENTENCE = 4;
- int JURY = 5;
- String[] lines = loadStrings(fileName);
- for (int i = 0; i < lines.length; i++) {
- String[] tokens = split(lines[i], ';');
- if (tokens.length != 6) {
- println("problem on line: "+i);
- continue;
- }
- int startTime = int(tokens[START_MILLIS]);
- int endTime = int(tokens[END_MILLIS]);
- String sentence = tokens[SENTENCE];
- int jury = int(tokens[JURY]);
- if (jury <= 0) {
- continue;
- }
- // -1 omdat de eerste index van een array 0 is
- Jury j = jurys.get(jury-1);
- j.sentences.add(new Sentence(sentence, startTime, endTime));
- }
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- class Jury {
- int id;
- ArrayList<Sentence> sentences;
- int playIndex = 0;
- Jury(int id) {
- this.id = id;
- sentences = new ArrayList<Sentence>();
- }
- }
- // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- class Sentence {
- String sentence;
- int startTime;
- int endTime;
- boolean triggered = false;
- Sentence(String sentence, int startTime, int endTime) {
- this.sentence = sentence;
- this.startTime = startTime;
- this.endTime = endTime;
- }
- }
1