use Writer.frink // This program generates color illusions like this: // http://www.johnsadowski.com/big_spanish_castle.php inputURL = "file:DSC_0077.JPG" img_in = new image[inputURL] // Get file part of URL to use for output files. origFile = urlFile[inputURL] greyFile = origFile greyFile =~ %s/(.*)\.\w+$/$1grey.jpg/ colorFile = origFile colorFile =~ %s/(.*)\.\w+$/$1colors.jpg/ htmlFile = origFile htmlFile =~ %s/(.*)\.\w+$/$1.html/ Width = img_in.getWidth[] Height = img_in.getHeight[] reverseImg = new image[Width, Height] greyImg = new image[Width, Height] for w = 0 to Width-1 { for h = 0 to Height-1 { [r,g,b] = img_in.getPixel[w, h] // This converts to YUV space using the BT. 709 definition used in // HDTV. See http://en.wikipedia.org/wiki/YUV y = 0.2126 r + 0.7152 g + 0.0722 b u = -0.09991 r - 0.33609 g + 0.436 b v = 0.615 r - 0.55861 g - 0.05639 b // Write out the grayscale levels. greyImg.setPixel[w, h, y, y, y] // Now we're going the throw away the Y (luminance) component // and replace it with a constant 0.5. Then we're going to go back to // RGB space and reverse the colors. We could simplify these equations // but it's kinda nice to see them in this form. y = 0.5 r = y + 0 u + 1.28033 v g = y - 0.21482 u - 0.38059 v b = y + 2.12798 u - 0 v reverseImg.setPixel[w, h, 1-r, 1-g, 1-b] } } g = new graphics g.fitCenter[reverseImg, 0, 0, 1, 1] g.drawEllipseCenter[0,0,0.005, 0.005] //win = g.show[Width, Height] g.write[colorFile, Width, Height] g1 = new graphics g1.fitCenter[greyImg, 0, 0, 1, 1] g1.drawEllipseCenter[0,0,0.005, 0.005] g1.write[greyFile, Width, Height] // Render an interactive HTML file println["htmlFile is $htmlFile"] html = new Writer[htmlFile] html.write["""
Stare at the dot for 30 seconds, then move your mouse over the image.