// This program was part of an April Fool's joke that I posted in April 2011. // see https://futureboy.us/temp/pigraph.html // // This is an implementation of Tupper's "self-referential" formula in Frink. // See: // http://en.wikipedia.org/wiki/Tupper%27s_self-referential_formula // // This program reads in a (black and white) graphic from an image file // and converts it to a number that can be plotted with Tupper's formula, // appropriately modified for width and height. Note that the equation I use // below is actually a simplified version of Tupper's formula that just plots // each pixel directly. f = new image["file:copyright.png"] width = f.getWidth[] height = f.getHeight[] println["image is $width x $height"] num = 0 for x = width-1 to 0 step -1 for y = 0 to height-1 { num = num * 2 if f.getPixelGrayInt[x,y] < 128 num = num + 1 } num = num*height println["n = $num"] println["Graph the points"] println[" 0 <= x < $width,"] println[" n <= y < n+$height,"] println[" where"] println[" 1/2 > floor(mod(floor(y/$height)*2^(-$height*floor(x)-mod(floor(y), $height)),2))"] // Now graph the number again just to make sure everything went right. g = new graphics for x=0 to width-1 for y = num to num+height-1 { // v = floor[(floor[y/height] 2^(-height floor[x] - floor[y] mod height)) mod 2] v = ((y/height) * 2^(-height x - (y mod height))) mod 2 if v >= 1 g.fillRectCenter[x,-y,1,1] } g.show[]