## Pi as an image

**Moderators:** phlip, Moderators General, Prelates

- cmacis
**Posts:**754**Joined:**Wed Dec 13, 2006 5:22 pm UTC**Location:**Leeds or Bradford, Thessex-
**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.

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.

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?

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**Location:**Leeds or Bradford, Thessex-
**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.

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.

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**Location:**Leeds or Bradford, Thessex-
**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

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.

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.

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.

- cmacis
**Posts:**754**Joined:**Wed Dec 13, 2006 5:22 pm UTC**Location:**Leeds or Bradford, Thessex-
**Contact:**

And making sure all is installed right and that I've made all the right additions to my path.

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.

- 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.

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.

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.

### Who is online

Users browsing this forum: Sizik and 1 guest