View or download TupperGen.frink in plain text format
// 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
[r,g,b] = f.getPixel[x,y]
if r < 1/2
num = num + 1
}
num = num*height
println["num is $num"]
// 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[]
View or download TupperGen.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen was born 18863 days, 3 hours, 49 minutes ago.