We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello.
I'm trying to make an experiment where I need to show a national flag for only 16 or 18 milliseconds, inmmediately followed by a 300 milliseconds mask. I thought that millis() was a good solution. But it seems to me that sometimes the flag is not showed. I don't know why. Maybe I have to change the frame rate, or millis() is not reliable. Dou you have any idea about why that happens? Thank you very much.
This is the code:
Flag Spain;
Mask mask;
PImage img;
float scale;
void setup() {
fullScreen();
noStroke();
scale = displayHeight/10;
Spain = new Flag();
mask = new Mask();
img = loadImage ("pic4.png");
frameRate(64);
}
void draw() {
background (255, 234, 150);
Spain.showFlag();
mask.showMask();
}
void keyPressed() {
if (key == 'e' || key == 'E') {
exit();
}
}
class Flag {
void showFlag() {
if(millis() > 2000 && millis() <=2100) {
rectMode(CENTER);
colorMode(RGB, 255, 255, 255);
fill(255, 0, 17);
rect(displayWidth/2, (displayHeight/2)-33, 134, 22);
rect(displayWidth/2, (displayHeight/2)+33, 134, 22);
fill(255, 234, 0);
rect(displayWidth/2, (displayHeight/2), 134, 44);
}
}
}
class Mask {
void showMask() {
if (millis() > 2016 && millis() < 2316) {
imageMode(CENTER);
image(img,displayWidth/2, displayHeight/2, 134, 88);
}
}
}
Answers
16 milliseconds is just a single frame. Depending on the exact timing of a frame, 16 milliseconds might elapse between two frames.
If you really need that exact timing, use the
frameCount
variable instead. But note that a single frame is going to be pretty hard to see.Thanks KevinWorkman.
frameCount
works very well. In fact, it would be perfect if almost nobody can see the frame.Finally I could not use
frameCount
. I needed to create a experiment where people has to answer questions after subliminal exposure to some simbols (a national flag, for example). The subliminal image is masked by another one. In order to assure that people is looking at the screen, they have to anticipate where the next question will appear and press up or down keys according to it. After that, they have to answer the question. It was very difficult to combine all that things. I had to use a trick to show the flag only for 16 milliseconds: I usedmillis()
and pictures to make the animation. Maybe you can find a more nice and elegant solution. My code:subliminalFlag.pde
Flag2.pde
Just to warn you -- this is not a very reliable setup at all, because the sketch will do its best to display each frame as close to the rate as it can (or later if it must) -- over time it will drift off the clock, and even other applications running on the same computer could cause frame lags.
If you really need to simulate a 16ms "tachistoscope" window for the purposes of a perception study then you need a computer and a display that can refresh the screen much faster than 60fps -- for example, a 120fps sketch running on a 120Hz monitor would be better.
Also, your display matters (for example -- screen tearing or afterimage could affect your results significantly).
Thank you jeremydouglass. That's very kind of you. I will take your warning into account.