Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Sourcecode for: Deconstruction of Optical Illusions
int main (int argc, const char * argv[])
{
@autoreleasepool {
YAVector2i *res = [[YAVector2i alloc] initVals: 800 : 800];
float defGrey = 150.0f / 255.0f;
YAVector4f *backColor = [[YAVector4f alloc] initVals: defGrey : defGrey : defGrey : 1];
YACanvas *canvas = [[YACanvas alloc] initResolution: res Color: backColor];
YAVector3f *light = [[YAVector3f alloc] initVal: 209.0 / 255.0];
YAVector3f *dark = [[YAVector3f alloc] initVal: 85.0 / 255.0];
int cSpan = 50;
int cSpanH = cSpan / 2;
YAVector2i *pA = [YAVector2i new];
YAVector2i *pB = [YAVector2i new];
YABlob *blob = [[YABlob alloc] initCanvas: canvas];
[blob.color setVector: light];
blob.radius = 6;
int swubS = 2;
// Grid
for(int xx = 1; xx < res.x / cSpan; ++xx) {
for(int yy = 1; yy < res.y / cSpan; ++yy) {
int x = xx * cSpan;
int y = yy * cSpan;
if( (xx == 5 && yy > 4 && yy < 14) ||
(xx == 14 && yy > 4 && yy < 14) ||
(yy == 5 && xx > 4 && xx < 14) ||
(yy == 14 && xx > 4 && xx < 15) )
continue;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) {
pA.x = x; pA.y = y; pB.x = x; pB.y = y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x + cSpanH; pA.y = y; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x + cSpanH; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x; pA.y = y + cSpan; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x + cSpanH; pA.y = y + cSpan; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x; pA.y = y; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x + cSpanH; pA.y = y; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x + cSpan; pA.y = y; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x + cSpanH; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x + cSpan; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
} else {
pA.x = x; pA.y = y; pB.x = x; pB.y = y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x + cSpanH; pA.y = y; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x + cSpanH; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x; pA.y = y + cSpan; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x + cSpanH; pA.y = y + cSpan; pB.x = pA.x; pB.y = pA.y;
pB.x += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.y -= swubS; else pB.y += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x; pA.y = y; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x + cSpanH; pA.y = y; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x + cSpan; pA.y = y; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: light];
pA.x = x + cSpanH; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: dark];
pA.x = x + cSpan; pA.y = y + cSpanH; pB.x = pA.x; pB.y = pA.y;
pB.y += cSpanH;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) pB.x -= swubS; else pB.x += swubS;
[canvas plotLineAA: pA To: pB Color: light];
}
}
}
YAVector2f *lightA = [[YAVector2f alloc] initVals: 1.0 : -1.0];
[lightA normalize];
YAVector2f *lightB = [[YAVector2f alloc] initVals: -1.0 : 1.0];
[lightB normalize];
YAVector2f *lightC = [[YAVector2f alloc] initVals: 1.0 : 1.0];
[lightC normalize];
YAVector2f *lightD = [[YAVector2f alloc] initVals: -1.0 : -1.0];
[lightD normalize];
for(int xx = 1; xx < res.x / cSpan; ++xx) {
for(int yy = 1; yy < res.y / cSpan; ++yy) {
int x = xx * cSpan;
int y = yy * cSpan;
if( (xx == 5 && yy > 4 && yy < 14) ||
(xx == 14 && yy > 4 && yy < 14) ||
(yy == 5 && xx > 4 && xx < 14) ||
(yy == 14 && xx > 4 && xx < 15) )
continue;
if(xx > 5 && xx < 14 && yy > 5 && yy < 14) {
pA.x = x; pA.y = y; [blob lightAt: pA Light: lightC];
pA.x += cSpanH; [blob lightAt: pA Light: lightD];
pA.x = x; pA.y = y; pA.y += cSpanH; [blob lightAt: pA Light: lightD];
pA.x += cSpanH; [blob lightAt: pA Light: lightC];
pA.x = x; pA.y = y; pA.x += cSpan; [blob lightAt: pA Light: lightC];
pA.y += cSpan; [blob lightAt: pA Light: lightC];
pA.x = x; pA.y = y; pA.x += cSpan; pA.y += cSpanH; [blob lightAt: pA Light: lightD];
pA.x = x; pA.y = y; pA.y += cSpan; [blob lightAt: pA Light: lightC];
pA.x = x; pA.y = y; pA.x += cSpanH; pA.y += cSpan; [blob lightAt: pA Light: lightD];
} else {
pA.x = x; pA.y = y; [blob lightAt: pA Light: lightA];
pA.x += cSpanH; [blob lightAt: pA Light: lightB];
pA.x = x; pA.y = y; pA.y += cSpanH; [blob lightAt: pA Light: lightB];
pA.x += cSpanH; [blob lightAt: pA Light: lightA];
pA.x = x; pA.y = y; pA.x += cSpan; [blob lightAt: pA Light: lightA];
pA.y += cSpan; [blob lightAt: pA Light: lightB];
pA.x = x; pA.y = y; pA.x += cSpan; pA.y += cSpanH; [blob lightAt: pA Light: lightB];
pA.x = x; pA.y = y; pA.y += cSpan; [blob lightAt: pA Light: lightA];
pA.x = x; pA.y = y; pA.x += cSpanH; pA.y += cSpan; [blob lightAt: pA Light: lightB];
}
}
}
[canvas writeJPGTo: @"Opti_B.jpg"];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment