We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to write using the normal letters of the keyboard, but instead of letters I want images. I know how to associate a letter to an image. But for now, I want to know how can I write without the letters stay overlapping. This is what I have so far. Please help me!
int rectWidth;
//int segundos = 30;
//int frate = 50;
//int cont = 2;
void setup() {
size(640, 360);
noStroke();
background(#FFFFFF);
rectWidth = width/4;
}
void draw() {
// keep draw() here to continue looping while waiting for keys
// save("imagem"+cont+".jpg");
// cont++;
}
void keyPressed() {
int keyIndex = -1;
if (key >= 'A' && key <= 'Z') {
keyIndex = key - 'A';
} else if (key >= 'a' && key <= 'z') {
keyIndex = key - 'a';
}
if (keyIndex == -1) {
// If it's not a letter key, clear the screen
background(#FFFFFF);
} else {
fill(#000000);
textSize(160);
text(key, random(550), 240);
print (key);
}
}
Answers
Did you mean to show your code? Please edit your post, paste in your code, highlight the code and press CTRL+o to indent. This will help forum members read it, run it, and give feedback.
https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text#latest
I was asking how can I create a code using processing to type/write normally, because what I have right now, just allowed me to type/write, but the with the letters overlapping.
yes, but you had to format your code so we could read it before we could see what you were doing.
this is the bit displaying the letters
so you are printing the new character at a random position on line 240. to stop this you have to control the x position. maybe start at 0 and move to the right with each letter...
Can you explain me how to control the x position, please?
https://processing.org/tutorials/drawing/
text()
to see how the x argument is defined:https://processing.org/reference/text_.html
But if I take the random it's impossible to write This is what happen with the code that I have.
Try these:
Show text at a random x:
Show text at x=100: (same place every time)
Show text based at an x based on what second it currently is (0-59):
...did you try them?
Okay, now: @koogs is suggesting that you instead do something like this:
...but now you need to define x as a variable somewhere before using it, and every time you press a key, you need to increase x by some amount -- e.g.
x=x+10;
-- like a cursor moving forward.Now, the letters just stay overlapping in the same place :s
Re-read the end of my answer.
depending on the size of the letters 10 pixels might not be enough. try a bigger value.
best of all would be to modify the increment based on the width of the new letter... (using textWidth())