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];
YAVector4f *backColor = [[YAVector4f alloc] initVals: 0.99 : 0.99 : 0.99 : 1];
YACanvas *canvas = [[YACanvas alloc] initResolution: res Color: backColor];
float lineW = 9;
float lineSP = res.x / 25;
YAVector2i *startPos = [YAVector2i new];
YAVector2i *endPos = [YAVector2i new];
YAVector3f *gridCol = [[YAVector3f alloc] initVal: 0.5];
startPos.y = 0;
endPos.y = res.y - 1;
for(int x = lineSP / 2; x < res.x; x += lineSP ) {
startPos.x = x; endPos.x = x; [canvas plotLine: startPos To: endPos Color: gridCol Width: lineW];
}
startPos.x = 0;
endPos.x = res.x - 1;
for(int y = lineSP / 2; y < res.y; y += lineSP ) {
startPos.y = y; endPos.y = y; [canvas plotLine: startPos To: endPos Color: gridCol Width: lineW];
}
startPos.y = 0;
endPos.y = res.y - 1;
for(int x = - res.x + lineSP; x < res.x; x += lineSP * 2) {
startPos.x = x; endPos.x = x + res.x; [canvas plotLine: startPos To: endPos Color: gridCol Width: lineW / 2.0f];
}
for(int x = lineSP - floorf(lineW / 2.) ; x < res.x * 2; x += lineSP * 2) {
startPos.x = x; endPos.x = x - res.x; [canvas plotLine: startPos To: endPos Color: gridCol Width: lineW / 2.0f];
}
YAVector2i *blobRes = [[YAVector2i alloc] initVal: 13];
YAVector2i *origin = [[YAVector2i alloc] initVal: (lineSP / 2) - 2];
YABlob* blobB = [[YABlob alloc] initCanvas: canvas];
[blobB.color setValue: 1.0];
blobB.radius = 6.0f;
YABlob* blobA = [[YABlob alloc] initCanvas: canvas];
[blobA.color setValue: 0.03];
blobA.radius = 5.0f;
YAVector2i *blobPos = [YAVector2i new];
[blobRes sweep: ^(YAVector2i *pos) {
if(pos.x % 2 == 0 && pos.y % 2 == 0) {
blobPos.x = pos.x * 2 * lineSP + origin.x;
blobPos.y = pos.y * 2 * lineSP + origin.y;
[blobB drawAt: blobPos];
[blobA drawAt: blobPos];
}
}];
[canvas writeJPGTo: @"Opti_A.jpg"];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment