## Pi as an image

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

cmacis
Posts: 754
Joined: Wed Dec 13, 2006 5:22 pm UTC
Contact:

### Pi as an image

It's been too long for me and writing code. I want digits of pi representing as pixels. Since pixels are based on binary I'm calculating 10^6 digits of pi in hex. Then, how to get that into an image?

Might do an easier one and interperet digits in base 4 as move up,down,left or right. got some etch a sketch code here somewhere.

Digits are calculated and come in at under a meg. pm me and i'll forward you it if you like the challenge.
li te'o te'a vei pai pi'i ka'o ve'o su'i pa du li no
Mathematician is a function mapping tea onto theorems. Sadly this function is irreversible.
QED is Latin for small empty box.
Ceci nâ€™est pas une [s]pipe[/s] signature.

warriorness
Huge Fucking-Lazer
Posts: 1610
Joined: Thu Dec 28, 2006 10:33 am UTC
Location: CMU, Pittsburgh, PA, USA
Contact:
I remember I had a discussion about this with a friend at school once. We changed some bytes in a BMP file, and it turns out that even most BMPs are compressed some. If I'm not mistaken, you'd need to make a RAW image...

Granted knowledge of how the image format is done, though, I'm sure it could be done in almost any language. Why not upload a text file for anybody to have a crack at it?
Iluvatar wrote:Love: Gimme the frickin' API.
yy2bggggs, on Fischer Random chess wrote:Hmmm.... I wonder how how a hypermodern approach would work

cmacis
Posts: 754
Joined: Wed Dec 13, 2006 5:22 pm UTC
Contact:
Sure, just find a place to store it first.
100 digits put into base 4 and passed to my old etch a sketch midlet.
li te'o te'a vei pai pi'i ka'o ve'o su'i pa du li no

Mathematician is a function mapping tea onto theorems. Sadly this function is irreversible.

QED is Latin for small empty box.

Ceci nâ€™est pas une [s]pipe[/s] signature.

cmacis
Posts: 754
Joined: Wed Dec 13, 2006 5:22 pm UTC
Contact:
http://mypaidtoread.bravehost.com/pi.txt the million digits taken into base 16

http://mypaidtoread.bravehost.com/pi4.txt the hundred digits in base 4
li te'o te'a vei pai pi'i ka'o ve'o su'i pa du li no

Mathematician is a function mapping tea onto theorems. Sadly this function is irreversible.

QED is Latin for small empty box.

Ceci nâ€™est pas une [s]pipe[/s] signature.

WhiteRabbit
Railgun of Infinite Patience
Posts: 242
Joined: Fri Oct 20, 2006 2:30 pm UTC
Contact:
warriorness wrote:We changed some bytes in a BMP file, and it turns out that even most BMPs are compressed some.

You found a compressed .bmp? That's weird. I don't think I have ever ran into one that isn't type 0. Anyway, you can find the specification for .bmp's here, but you might be more interested in .ppm's.

Drostie
Posts: 262
Joined: Fri Nov 03, 2006 6:17 am UTC
You can do it easily in TIFFs or PPMs. I'd say, go with PPMs. I've never dealt with direct BMP output, but I suspect it'd be easy, too (but you can read a PPM with GIMP and then export it to BMPs anyway, so, whichever).

PPM is easiest.

Lets suppose you want a 1024x768 desktop background, full color. You'll need 3 color values per pixel, each one takes up two digits of hex, so,you'll need a total of 4,718,592 hex digits of pi. Except that's not quite right, because the opening 3 is probably going to be 000003 on the first pixel, so you'll only need 4,718,586 more hex-digits, to go with the decimal expansion.

To write the actual file, first, write the header, which is the ASCII character string of:

Code: Select all

`P6\n1024 768\n255\n`

Then, stop writing to the file in ASCII, and start writing in raw bytes. Write the numbers 0,0,3 to the file at first; then get the remaining 2,359,293 bytes from the program you're using to calculate pi.

Close the file, saved as pi.ppm, and open it with the GIMP. Voila, done.

Posts: 274
Joined: Fri Nov 10, 2006 6:08 am UTC
Location: Wouldn't you rather know how fast I'm going?
Contact:
I have done it. Apologies for the accuracy; pixels are not the greatest representation of data.

lewis1350
Posts: 18
Joined: Tue Mar 20, 2007 1:10 am UTC
Location: At My Computer
Contact:
adlaiff6 wrote:I have done it. Apologies for the accuracy; pixels are not the greatest representation of data.

Wasn't expecting that.

Drostie
Posts: 262
Joined: Fri Nov 03, 2006 6:17 am UTC

Java source code to create a ppm of whatever size you want is here. It requires apfloat to be installed to work properly.

cmacis
Posts: 754
Joined: Wed Dec 13, 2006 5:22 pm UTC
Contact:
yay!
Now to remember how to compile normal java.
li te'o te'a vei pai pi'i ka'o ve'o su'i pa du li no

Mathematician is a function mapping tea onto theorems. Sadly this function is irreversible.

QED is Latin for small empty box.

Ceci nâ€™est pas une [s]pipe[/s] signature.

Rysto
Posts: 1459
Joined: Wed Mar 21, 2007 4:07 am UTC
javac whatever.java?

cmacis
Posts: 754
Joined: Wed Dec 13, 2006 5:22 pm UTC
Contact:
And making sure all is installed right and that I've made all the right additions to my path.
li te'o te'a vei pai pi'i ka'o ve'o su'i pa du li no

Mathematician is a function mapping tea onto theorems. Sadly this function is irreversible.

QED is Latin for small empty box.

Ceci nâ€™est pas une [s]pipe[/s] signature.

Drostie
Posts: 262
Joined: Fri Nov 03, 2006 6:17 am UTC
It kind of just looks like noise, though. It might be more interesting to do something like generating Perlin Noise from pi, and then create a 2d image out of *that*.

musicinmybrain
Posts: 96
Joined: Sun Dec 31, 2006 2:50 am UTC
Location: Greensboro, NC

silverhammermba
Posts: 178
Joined: Fri Oct 13, 2006 1:16 am UTC
I think that one of the biggest problems with visualizing pi comes before any coding - it is that pretty much every method will be almost entirely arbitrary and irrelevant to the meaning of pi (other than a circle, that is).

For example, a box where each pixel represents a digit would look very different if you simply changed the dimension of the box or the method in which the digits where ordered.

Of all of the methods shown in musicinmybrain's link, I think that my favorite is the one where each digit is interpreted to be a direction to walk in - since it shows a kind of progression. If you were to switch the direction corresponding to each digit, the image would remain largely unchanged (simply translated or flipped in some way).

The key, I think, is to the think of a method in which the result will be somewhat consistent regardless of how much the specifics of the method are modified.

yy2bggggs
Posts: 1261
Joined: Tue Oct 17, 2006 6:42 am UTC
adlaiff6 wrote:I have done it. Apologies for the accuracy; pixels are not the greatest representation of data.

Bah!
IOCCC winner 1988 best layout (by Brian Westley):

Code: Select all

`#define _ F-->00 || F-OO--;long F=00,OO=00;main(){F_OO();printf("%1.3f\n", 4.*-F/OO/OO);}F_OO(){            _-_-_-_       _-_-_-_-_-_-_-_-_    _-_-_-_-_-_-_-_-_-_-_-_  _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-__-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_  _-_-_-_-_-_-_-_-_-_-_-_-_-_    _-_-_-_-_-_-_-_-_-_-_-_       _-_-_-_-_-_-_-_-_            _-_-_-_}`

To increase accuracy, make a bigger circle.