Pixelcheck on screen

Hey I want to highlight one after another pixel on the screen in a different color than the backround for each pixel.
the backround of the screen will be white and the then one after another pixel should be highlighted in another color. The pixel should be highlighted for about 0.5s maximal, maybe less, but should be white after that again. If I use the Sleep(0.5) the hole screen stays black for the amount of pixels multiplied by 0.5s ?
Could you tell me what I did wrong and why i cant see the progress if I run the program?

void ofApp::draw() {

  // make white plane
  ofSetColor(255, 255, 255);
  ofDrawRectangle(0, 0, 1920, 1080);

  // get screen resolution
  int horizon = ofGetWindowWidth();
  int vert = ofGetWindowHeight();
  // output of screen resolution for testing
  string text = "width " + to_string(horizon) + " height " + to_string(vert);
  ofDrawBitmapStringHighlight(text,ofPoint(10,10,0.0),ofColor::white,ofColor::black );

  ofColor::red;
  ofDrawSphere(100,100, 1);
  Sleep(2500);
  ofColor::white;
  ofDrawSphere(100, 100, 1);
  Sleep(2500);
  ofColor::red;
  ofDrawSphere(200, 200, 1);
  Sleep(2500);
  ofColor::white;
  ofDrawSphere(200, 200, 1);
  Sleep(2500);

  /*  for (int i = 0; i <= horizon; i++) 
  {
    for (int j = 0; j <= vert; j++)
    {
      ofColor::white;
      ofDrawSphere(i, j, 1);
      Sleep(500);
      ofColor::red;
      ofDrawSphere(i, j, 1);
    }
  }*/
}

later I want to run the bottom loop instead of the test scanrio with 2 pixels

EDIT: is it even possible to do this with the draw function or am I allowed to work with this like an image? To precise my issue: I want to render every ~0.5sec a new frame in which a specified pixel goes from (0,0) to (0,1)… like in the 2 for-loops. Or do I have to work totally differently and write function that calls void ofApp::draw() every 0.5sec with changing initial values

You won’t see any effect of your drawing commands until the end of draw() so basically what you are doing now is telling it to draw all of the pixels at once, you’re just telling it in a slow way because of your sleep commands.

Try updating the x and y in theupdate function instead:

setup(){
    ofSetBackgroundColor(255);
    x = 0;
    y = 0;
}

update(){
    x++;
    if(x > ofGetWidth()){
        x = 0;
        y++;
    }
}

draw(){
    ofSetColor(255, 0, 0);
    ofDrawRectangle(x, y, 1, 1);
}

By the way, if you’re just drawing a point, you can use something like ofDrawRectangle(x, y, 1, 1), which draws less complex geometry than a sphere (which actually is a 3d object).
Also, you don’t need to draw a white rectangle every frame. The screen gets cleared automatically every frame. You can set the clear color using ofSetBackgroundColor() (or disable this using ofSetBackgroundAuto(false))

thank you, it’s workin now :slight_smile:

can you maybe help me why it doesn’t work that it’s starts from begin if I add this short if in the update function.

 if (ofGetWindowHeight() < y && ofGetWindowWidth() < x) {
    x = 0;
    y = 0;
  } 

and do you have an idea how i can work the c++ spiral algorithm from this question into my code.

if X is DisplayWidth and Y is DisplayHeight

void Spiral( int X, int Y){
    int x,y,dx,dy;
    x = y = dx =0;
    dy = -1;
    int t = std::max(X,Y);
    int maxI = t*t;
    for(int i =0; i < maxI; i++){
        if ((-X/2 <= x) && (x <= X/2) && (-Y/2 <= y) && (y <= Y/2)){
            // DO STUFF...
        }
        if( (x == y) || ((x < 0) && (x == -y)) || ((x > 0) && (x == 1-y))){
            t = dx;
            dx = -dy;
            dy = t;
        }
        x += dx;
        y += dy;
    }
}

This way the pixel will run from the center like a spiral outside i was thinkin about workin this into the update function but for me it isn’t clear how to go into the draw function when i want to. or do i just call draw() ?
I also thought of continue but I heard it’s not the safest call…

This might be a personal preference, but to me this line:

if (ofGetWindowHeight() < y && ofGetWindowWidth() < x) {

reads a bit odd because ofGetWindowHeight() will not really change (unless you scale the window). You are manipulating x and y, so to me, it makes more sense to put those values first in your comparison:

if (y > ofGetWindowHeight() && x > ofGetWindowWidth()) {

Again, this might just be a preference (the outcome of the two versions is the same)

To know why the code isn’t working, I need to see where you’ve placed it. For instance, the below code won’t work because you’ve already reset the value of x and y, meaning they will never become larger than your screen at the point where you check:

update(){
    x++;
    if(x > ofGetWindowWidth()){
        x = 0;
        y++;
    }
    // when you reach this point, x has already been changed and will never be 
    // larger than ofGetWindowWidth()
    if (y > ofGetWindowHeight() && x > ofGetWindowWidth()) {
        x = 0;
        y = 0;
    }
}

You already have a check to make sure x gets reset to 0 if it becomes too large. So for your new function to work you only have to check the value of y:

update(){
    // this part stays the same
    x++;
    if(x > ofGetWindowWidth()){
        x = 0;
        y++;
        // this check is new
        if(y > ofGetWindowWidth()){
            y = 0;
        }
    }
}

thanks for these remarks. yeah the style-thing you’re saying is maybe better language too i guess. I’ll try to follow this remarks! For the solution itself I had a new idea and now I’m going like a spiral threw the frame :wink:

this is running fine :slight_smile: if you’ve interest i could post my Code here.

Maybe you could answer me another question. I integrated the picture of my webcam into the solution and I’m that far that I could clone the actual frame into another object. But I want that actual picture to be ofxCvGrayscaleImage . For that I think I need to understand that first. Does it is still a NxMx4 matrix with the same value in the 4 layers?
I want to compare the webcam picture with the image on the screen I’m producing myself…

regards :wink: