qwerty
November 21, 2019, 9:56am
1
Hello. Today i’ve searching the Internet for the new Processing tutorials and found this one:
void setup() {
size(400, 400);
background(#3355CC);
}
void draw() {
fill(#3355CC, 20);
rect(0, 0, width, height);
}
void keyPressed() {
fill(#FFE200);
textSize(random(20, 200));
text(key, random(300), random(100, 400));
}
… but this code is not working correctly in my Processing 3.5.3 environment. I mean sometimes it’s works and sometimes it’s not (no any outputs on the screen). Just run it about five times, press some keys and you will see that by yourself. But why is so strange behavior?
noel
November 21, 2019, 10:40am
2
I’ve tried it with mousePressed, because I am working on a tablet. For me it’s working alright. Just a guess.These are two different events. Try using noLoop() end loop() in keyPressed()
kll
November 21, 2019, 10:59am
3
sorry, but if you start from any tutorial / example /…
better give a link here…
can i for your code and @noel comment add,
that you should be aware of that what i call
void setup(){
size(200,200);
}
void draw() {
background(200,200,0);
fill(0);
text("text",10,10);
}
if you would try to draw from key/mousePressed anything it will not work
OR like from your tutorial
void setup(){
size(200,200);
background(200,200,0);
}
void draw() {
}
void keyPressed() {
fill(0);
text("text",10,10);
}
so what is the difference?
it is WHERE the
background()
command is, erasing the screen/canvas
1 Like
noel
November 21, 2019, 11:20am
4
So why does it draw perfectly on my tablet?
kll
November 21, 2019, 11:22am
5
sorry, that comment is related to above draw mode info,
where the draw has a background command…
NOT to your code…
so i failed to describe the 2 mode thinking??
noel
November 21, 2019, 11:29am
6
Do you mean Processing mode? using logic to solve
A = C and B = C, is A = C?
kll
November 21, 2019, 11:31am
7
how YOU call it?
if the background command is
noel
November 21, 2019, 11:37am
8
I am confused. Isn’t
rect(0, 0, width, height);
the same as
background()?
1 Like
kll
November 21, 2019, 11:41am
9
still with using alpha in fill i would call it PAINT MODE ?
anyhow i love the fading idea.
noel
November 21, 2019, 11:44am
10
Yes you are right, but I would like to know the correct topic answer, because I think it’s a valid question.
kll
November 21, 2019, 11:50am
11
ahm,
for me ( win 10 / 64b // processing 3.5.3 )
it is very normal, that keyboard not works,
so i write a intro in setup like:
println("click on canvas and use: key [s] for save picture. ");
so my answer would be: get used to that you have to click with mouse first,
i never considered that as a BUG??? but yes.
it might also be related with the focused
problems.
https://processing.org/reference/focused.html
also not know if it is OS related??
1 Like
noel
November 21, 2019, 11:59am
12
Now I got it, on PC it really can go out of focus.
But if he tried several times, and stops after a few, how can it go out of focus?
Does it work on your PC?
kll
November 21, 2019, 12:03pm
13
possibly not go out of focus, i say from here
4 of 10 start a key press works
Tiemen
November 21, 2019, 12:06pm
14
Did you make sure that the window that pop ups right after running the sketch is selected? The sketch doesn’t respond to my keyboard unless I click in the window with my mouse.
Tiemen
November 21, 2019, 12:10pm
15
I think the terms draw and paint mode are good names. You redraw everything or you paint on top of the existing canvas.
1 Like
noel
November 21, 2019, 12:15pm
16
What does happen after that?
Could you try to put the noLoop loop in keyPressed?
For instance; when I draw in the event onBluetoothDataEvent(String who, byte[] data)
and use fill there, it will mess up with the draw() event, if I don’t use noLoop.
kll
November 21, 2019, 12:20pm
17
sorry i not play this,
but i know that keyPressed works as long there is a
draw(){}
independent on loop() or noLoop()
so a keyboard operation for loop() or redraw() ( from noLoop() ) is possible.
( besides above focused condition what also not works good in windows… )
__
now if we click on canvas we can use keyboard until click on other window ( or ALT TAB )
mouse position does not matter meanwhile(?)
something to play with
String usertxt="";
void setup () {
size(500, 500);
println("use: any key ");
fill(0);
}
void draw () {
surface.setAlwaysOnTop(true); // actually not helps for this problem
background(200,200,0);
if ( mousePresent && focused ) text("focus + see mouse",10,10);
if ( mousePresent ) text("see mouse",10,30);
text(usertxt,20,height/2);
}
void keyPressed() {
usertxt+=key;
}
boolean mousePresent=false;
//_ 2 nice build ins undocumented, not too helpful
// https://docs.oracle.com/javase/7/docs/api/java/awt/event/MouseListener.html#mouseEntered(java.awt.event.MouseEvent)
public void mouseExited() {
mousePresent = false;
}
public void mouseEntered() {
mousePresent = true;
}
noel
November 21, 2019, 12:36pm
18
So i went to my neighbours house to bother him, and tried it on his windows 7 64b computer… Unfortunately I could not reproduce the error. It worked perfectly.
kll
November 21, 2019, 1:03pm
19
like i show already
win 10 64b
4 of 10 start a key press works
noel:
windows 7 64b computer
i also tested on the old PC,
7 of 10 start a key press works
booted win7 32b ( & processing 3.5.3 32b )
8 of 10 start a key press works
so win10 is actually worst!
noel
November 21, 2019, 3:04pm
20
What happens with a lower frameRate?