Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Drawing pixels in Checkerboard pattern

$
0
0

@Przemyslaw_Trzaska wrote:

I’m trying to display pixels in Checkerboard pattern black and white. I understand that I need to find the end of the row and make offset 1 or 0 for each iteration. So that each time when the first loop ends the second starts with a white pixel or black pixel.
In my case pixels are in the same formation.

ofApp.h
ofTexture tex;
unsigned char pixels[200 * 200];
int OffSetX;
int OffSetY;

ofApp.cpp

[b]

void ofApp::setup(){
// fill the pixels array with white pixels
int size = sizeof(pixels) / sizeof(unsigned char);
//int row = (200 * 200) / 2;

for (int i = 0; i < size; i ++) {
	OffSetX = i + 1;
	for (int j = 0; j < size; j++) {
		OffSetY= (j + OffSetX)%2;
	
		if ((OffSetY+OffSetX) % 2 == 0) {

			pixels[j] = 255;

		}else{
			pixels[j] = 0;
			}


	}
}

tex.loadData(pixels, 200, 200, GL_LUMINANCE);

}
[/b]


void ofApp::draw(){
tex.draw(20, 20, 800, 800);
}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4929

Latest Images

Trending Articles



Latest Images