Pi as an image

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

Moderators: phlip, Prelates, Moderators General

Pi as an image

Postby cmacis » Mon Mar 26, 2007 5:42 pm UTC

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

Postby warriorness » Mon Mar 26, 2007 5:56 pm UTC

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
User avatar
warriorness
Huge Fucking-Lazer
 
Posts: 1610
Joined: Thu Dec 28, 2006 10:33 am UTC
Location: CMU, Pittsburgh, PA, USA

Postby cmacis » Mon Mar 26, 2007 6:22 pm UTC

Sure, just find a place to store it first. Image
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.
User avatar
cmacis
 
Posts: 754
Joined: Wed Dec 13, 2006 5:22 pm UTC
Location: Leeds or Bradford, Thessex

Postby cmacis » Mon Mar 26, 2007 6:28 pm UTC

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

Postby WhiteRabbit » Mon Mar 26, 2007 9:27 pm UTC

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.
User avatar
WhiteRabbit
Railgun of Infinite Patience
 
Posts: 242
Joined: Fri Oct 20, 2006 2:30 pm UTC

Postby Drostie » Tue Mar 27, 2007 12:36 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.
User avatar
Drostie
 
Posts: 262
Joined: Fri Nov 03, 2006 6:17 am UTC

Postby adlaiff6 » Tue Mar 27, 2007 1:59 am UTC

I have done it. Apologies for the accuracy; pixels are not the greatest representation of data.

Image
User avatar
adlaiff6
 
Posts: 274
Joined: Fri Nov 10, 2006 6:08 am UTC
Location: Wouldn't you rather know how fast I'm going?

Postby lewis1350 » Tue Mar 27, 2007 2:41 am UTC

adlaiff6 wrote:I have done it. Apologies for the accuracy; pixels are not the greatest representation of data.

Image

Wasn't expecting that. :mrgreen:
User avatar
lewis1350
 
Posts: 18
Joined: Tue Mar 20, 2007 1:10 am UTC
Location: At My Computer

Postby Drostie » Tue Mar 27, 2007 6:32 pm UTC

Image

Java source code to create a ppm of whatever size you want is here. It requires apfloat to be installed to work properly.
User avatar
Drostie
 
Posts: 262
Joined: Fri Nov 03, 2006 6:17 am UTC

Postby cmacis » Tue Mar 27, 2007 9:08 pm UTC

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

Postby Rysto » Wed Mar 28, 2007 2:16 am UTC

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

Postby cmacis » Wed Mar 28, 2007 2:30 am UTC

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

Postby Drostie » Wed Mar 28, 2007 4:01 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*.
User avatar
Drostie
 
Posts: 262
Joined: Fri Nov 03, 2006 6:17 am UTC

Postby musicinmybrain » Fri Apr 06, 2007 12:14 am UTC

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

Postby silverhammermba » Mon Apr 09, 2007 6:07 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.
User avatar
silverhammermba
 
Posts: 179
Joined: Fri Oct 13, 2006 1:16 am UTC

Postby yy2bggggs » Mon Apr 09, 2007 6:28 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.
User avatar
yy2bggggs
 
Posts: 1261
Joined: Tue Oct 17, 2006 6:42 am UTC


Return to Coding

Who is online

Users browsing this forum: No registered users and 2 guests