How to use keyPressed() function or keyTyped() function?
in
Contributed Library Questions
•
11 months ago
Hi guys,
I tried to add in the keyTyped() function into the following code but it does not change the value of the string. Please advice.
import processing.opengl.*;
import geomerative.*;
RFont f;
RGroup grp;
RShape s;
float len;
float angle;
float pos;
// the error range for the tangent position and angle
float ANGLEERROR = 0.3;
float POINTERROR = 0;
float LENGTHTANGENT = 20;
// the initial text
String msg = "RShape";
String FONT = "lucon.ttf";
//the alpha value of the lines
int ALPHAVALUE = 10;
//the velocity of the calligraphy
int VELOCITY =10;
int MARGIN = 50;
void setup () {
size(500, 500, OPENGL);
background(255);
frameRate(25);
LENGTHTANGENT = LENGTHTANGENT * width/800F;
RG.init(this);
noFill();
stroke(0, 0, 0, 10);
f = new RFont(FONT, 372, RFont.CENTER);
initialize();
}
void draw() {
pushMatrix();
translate(width/2, height/2);
//Draw very low alpha and long tangents on random points of each letters
for (int i =0; i<grp.countElements(); i++) {
s = (RShape)(grp.elements[i]);
for (int j=0; j<s.countPaths();j++) {
for (int k=0;k<VELOCITY; k++) {
pos = random(0, 1);
RPoint tg = s.paths[j].getTangent(pos);
RPoint p = s.paths[j].getPoint(pos);
p.x = p.x +random(-POINTERROR, POINTERROR);
p.y = p.y +random(-POINTERROR, POINTERROR);
len = random(-LENGTHTANGENT, LENGTHTANGENT);
angle = atan2(tg.y, tg.x) + random(-ANGLEERROR, ANGLEERROR);
bezier(p.x, p.y, 10, 10, 90, 90, 15, 80);
}
}
}
popMatrix();
}
void initialize() {
grp = f.toGroup(msg);
grp.centerIn(g, MARGIN, 1, 1);
background(255);
}
void keyTyped() {
if(key==ENTER) {
msg="";
}
else {
msg+=key;
initialize();
}
}
I tried to add in the keyTyped() function into the following code but it does not change the value of the string. Please advice.
import processing.opengl.*;
import geomerative.*;
RFont f;
RGroup grp;
RShape s;
float len;
float angle;
float pos;
// the error range for the tangent position and angle
float ANGLEERROR = 0.3;
float POINTERROR = 0;
float LENGTHTANGENT = 20;
// the initial text
String msg = "RShape";
String FONT = "lucon.ttf";
//the alpha value of the lines
int ALPHAVALUE = 10;
//the velocity of the calligraphy
int VELOCITY =10;
int MARGIN = 50;
void setup () {
size(500, 500, OPENGL);
background(255);
frameRate(25);
LENGTHTANGENT = LENGTHTANGENT * width/800F;
RG.init(this);
noFill();
stroke(0, 0, 0, 10);
f = new RFont(FONT, 372, RFont.CENTER);
initialize();
}
void draw() {
pushMatrix();
translate(width/2, height/2);
//Draw very low alpha and long tangents on random points of each letters
for (int i =0; i<grp.countElements(); i++) {
s = (RShape)(grp.elements[i]);
for (int j=0; j<s.countPaths();j++) {
for (int k=0;k<VELOCITY; k++) {
pos = random(0, 1);
RPoint tg = s.paths[j].getTangent(pos);
RPoint p = s.paths[j].getPoint(pos);
p.x = p.x +random(-POINTERROR, POINTERROR);
p.y = p.y +random(-POINTERROR, POINTERROR);
len = random(-LENGTHTANGENT, LENGTHTANGENT);
angle = atan2(tg.y, tg.x) + random(-ANGLEERROR, ANGLEERROR);
bezier(p.x, p.y, 10, 10, 90, 90, 15, 80);
}
}
}
popMatrix();
}
void initialize() {
grp = f.toGroup(msg);
grp.centerIn(g, MARGIN, 1, 1);
background(255);
}
void keyTyped() {
if(key==ENTER) {
msg="";
}
else {
msg+=key;
initialize();
}
}
1