Get the latest tech news

The XOR Texture (2004)


int main(int argc, char *argv[]) { screen(256, 256, 0, "The XOR Texture"); for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) { Uint8 c = x ^ y; pset(x, y, ColorRGB(c, c, c)); } redraw(); sleep(); return 0; } int main(int argc, char *argv[]) { screen(256, 256, 0, "The XOR Texture"); ColorRGB color; for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) { Uint8 c = (x ^ y); color.r = 255 - c; color.g = c; color.b = c % 128; pset(x, y, color); } redraw(); sleep(); return 0; } int main(int argc, char *argv[]) { screen(256, 256, 0, "The XOR Texture"); ColorRGB color; for(int y = 0; y < h; y++) for(int x = 0; x < w; x++) { Uint8 c = (x ^ y); color = HSVtoRGB(ColorHSV(c, 255, 255)); pset(x, y, color); } redraw(); sleep(); return 0; }.

The XOR texture is simply generated by xor-ing the x and y coordinate of the current pixel. The maximum color value generated by the XOR operation is the same as the dimensions of the texture if its size is a power of two. Here's the result of XOR, AND and OR respectively:It makes sense that the AND texture is darker, because it returns 1 only in a single case.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of XOR Texture

XOR Texture