# Convert numbers to RGB

I’m trying to convert Pi into RGB values procedurally. My goal is to have enough pixels to make an image. Typing out thousands of RBG values manually isn’t going to work. Is there any way to do this quicker in Blender (with native tools, an add-on, or another program)?

A 1920x1080 image is like 2,0736 million digits in a table. You can probably find such a number online. I would probably look into figuring out how to program it and save it as an image, python maybe. I can’t imagine Blender being able to handle such precision. Maybe there is a way to calculate the n’th digit of pi directly, but I’m not a mathemagician so I wouldn’t have a clue.

Python seems like a good candidate for a solution. Thanks! I’m not very good at Python though, so some guidance is needed.

I haven’t done any programming since \$0314 and \$0315 was a thing (anyone get the reference by memory without looking it up? :D) I can’t give any guidance, but I’d look up any python specific forums or example code - gotta be a lot of pi related and image drawing stuff out there.

When editing the RGB node, here’s the code in the info editor. Can I put in variables instead of the RGB values? For starters…

``````bpy.data.materials["Material.003"].node_tree.nodes["RGB.012"].outputs[0].default_value = (0.4, 0.9, 0.1, 1)

``````

I’ll have a look for some other Pi pictures and example code.
Edit: Can’t find much. But still looking…

This is definitely a programming task that does not require Blender at all. Python again is the best solution as you can find modules like Pillow that will do all the heavy lifting for you and your final program will likely only be 20-30 lines of code. Pillow is a popular Python Image Library documented here:

and it should easily let you create an image of any size you like and then let you individually get and set pixels to whatever values you like. Google for python pillow examples.

If you don’t have Python already, I strongly recommend getting the (free) Anaconda distribution which will come with Pillow and everything else you could possibly need:

Just a word of warning: Pi is effectively random so any image produced from it is just going to be random colored noise, though maybe it will be more emotionally impactful if you can tell people “look, that’s Pi!”.

Have fun!

1 Like

Thank you for your help! I will check Pillow & Anaconda out.

The randomness of Pi is why I want to make it into images. You can find virtually any number in Pi because it’s never ending and random, so I was thinking you could probably find rare areas that resemble images too.

I was surprised when the first nine pixels of Pi where greens, blues, and browns that looked like a good natural color scheme. Because I was expecting a random rainbow of colors. I’m sure it gets more random later in the number though.

You don’t need Python. You can do this in nodes, natively.

Let’s look at your first color. Let’s consider this index 0, which will need to be some kind of input into your nodes. What is 0.1? It is pi * 10^(1+0+(index * 3)) , floored, divided by 10, fractioned. What is 0.4? It is pi * 10^(1+1+(index * 3)), floored, divided by 10, fractioned. What is 0.1? Pi * 10^(1+2+(index * 3)), floored, divided by 10, fractioned.

Let’s look at the second color. What are its RGB values? The same as above, except index is now 1.

Nodes are a programming language. The only thing missing is a loop/goto structure. Anything you can program without loops, you can program in nodes.

Is your goal to make a chart? You can run those nodes in compositing or in material nodes, either works. You could use modified texture coordinate values to determine the “index” input.

edit: But a few comments, because this isn’t a good technique for your stated goal.

First, computers do not know what the digits of Pi are any better than we do. Blender, in particular, knows them only to a fairly limited precision. You’re going to run out of digits pretty fast. After that, it’ll probably all be black.

Second, if what you want to do is look for images in noise, there are far easier methods. A white noise node gives random output. If you want three values, for RGB, look at three white noise nodes, each with a tiny vector offset.

I think I need way more than 5 decimal spaces of precision of pi to do what I’m trying. Blender lets you type in pi as a value, so do you know if it actually stores it as more than 5 decimals?

Online, they have millions of digits of pi. Is there any way to copy parts of that number into Blender?

Edited at same time. Check it out. Blender knows more than 5 digits of pi (try entering “pi” instead of numbers) but not enough for your purposes.

Edit: Oh, excuse me, entering pi into a value node is still just a shortcut for a few digits of pi, rather than the correct 32 bit floating point value.

Pretty sure you can find any finite number in the digits of Pi if you’re willing to look for a very long time

So also any discretely encoded image (all GIF, PNG, BMP, etc., images that are possible) will be guaranteed to exist in the digits of Pi (and each will be in there an infinite number of times).

Calculating Pi and digits of Pi is a game almost as old as circles, so you’ll find lots of data and sample programs out there. Python supports arbitrarily sized strings and integers (up to the amount of RAM you have available), so you can download a billion digits of Pi and load it into Python as a single string or even a single integer (after stripping off the “3.1” on the front) and Python will happily deal with it.

There are many algorithms for calculating the digits of Pi, and there’s even one that will let you directly calculate any digit of Pi that you want without computing the ones before it, so if you want the ten trillion trillionth digit of Pi that’s easy to get. The only catch is that the algorithm produces the Nth hexadecimal digit of Pi lol.

Again, there are zero reasons to do this in Blender unless you just want to use the Blender built-in Python for convenience, but using Blender nodes or functions will probably be a lot harder than a half-dozen lines of non-Blender Python.

1 Like

This screenshot perfectly sums up my level of Python experience.

In other news, I’m on the 49th pixel of Pi!

I tried grouping them by nines & it made some cool patterns in certain places.

Me learning to do this in Python might take a while because I’m a beginner.

ask question in Python forum or blender stack

you can modify directly an image on screen with python in blender
python works with double precision but internally blender use only single precision

interesting problem !

search python i think there is a script to calculate pi numbers
one example here

so should be possible to do a small script to do that !

let us know if you find something

happy bl

Not to be too much of a Debbie Downer, but there are a couple of flaws in your approach.

The first is a range problem. If you only map a single decimal digit to a color channel, you only have a 0.0-0.9 range. That means the darkest color you could possibly achieve would be pure black (R0.0, G0.0, B0.0), and the brightest would be a very light gray (R0.9, G0.9, B0.9). Your approach doesn’t allow for pure white (R1.0, G1.0, B1.0). How to fix this? You could remap your values 0 to 0.0 and 9 to 1.0, but at that point your are mathematically altering your Pi input which seems to defeat your premise.

Your next issue is a precision issue. If you only use one digit per color channel, you only have a maximum of 1,000 (10x10x10) pixel colors that you can generate. By contrast, an 8-bit per color channel pixel can have 16.7 million (256x256x256) possible colors. How to fix this? You could slice 3 digits (or more, depending on what amount of color accuracy you want) out for each color channel instead of 1 digit and then remap from 000 to 0 and 999 to 255, but that also causes problems. You would be giving up value space by mapping 000, 001, 002, and 003 all to 0. At that point, you are mathematically altering your input again and not directly representing pixel colors with Pi digits. You could go one more step to get (at least) those 8 bits (256 discrete values) per color channel by converting Pi into quaternary (base 4) and slicing 4 digits at a time for each channel. You’d still have to convert those 4 quaternary digits to decimal digits, but you wouldn’t be losing any precision from a mapping/rounding function. 0000 base-4 maps directly to 0 base-10. 3333 base-4 maps directly to 255 base-10. Take a look:

Quaternary (base-4) pi: 3.02100 33312 22202 02011 22030 02031 03010 30121 20220 23200 03130 01303 10102 21000 21032 00202 02212 13303 01310 00020 . . . (from here: https://robertlovespi.net/2014/06/09/the-beginning-of-the-number-pi-in-binary-through-hexadecimal-etc/)

Base-4 R: 0210 = Base-10 R: 36
Base-4 G: 0333 = Base-10 G: 63
Base-4 B: 1222 = Base-10 B: 106

Does that make sense or help at all?

2 Likes

No worries, everyone was a beginner once

Your problem there was you executed the python command which got you into the Python interactive prompt, and then tried to execute more commands that aren’t actually Python commands but operating system commands (most of which invoke Python).

From where you were entering exit() and at the >>> prompt would have exited you out of Python. You need an OS command prompt window to enter those commands in, not Python itself.

1 Like

you could assign one color per number between 0 and 9
then change a pixel to that color

at least that would give you some color variation for the different number in pi
don’t know if this would show some interesting pattern

another way might be to use these number and make some array
with number representing the Z value for a mesh or curve
it might be easier to see the patterns

happy bl

1 Like

Hi BlenderRender,

If it helps I’ve attached a text file (see pi.zip) with pi to 100,000 and 1M digits. Mathematica was used to generate this so it should be accurate. Good luck with your project, I am sure you will learn a lot of it. Also, you might consider other functions (or operations) that you could do on these digits. For example see:

Cheers and stay safe!

Pi.zip (506.7 KB)

2 Likes

depends how the op want to do it and how many numbers he wants to see

i rework the first 2 scripts to work in blender and they can generate pi numbers up to N numbers

only problem is that it build a list of txt number
so if you have a millions number that is a super long list
and would probably make PC get sluggish

on note if there are algo to generate pi numbers then it means there is some sort of pattern !

happy bl

did a small script to get some plane with colors
but with 1000 it is getting sluggish takes a few seconds to do it

3.14159265358979323846264338327950288419
7169399375105820974944592307816406286208
9986280348253421170679821480865132823066
4709384460955058223172535940812848111745
0284102701938521105559644622948954930381
9644288109756659334461284756482337867831
6527120190914564856692346034861045432664
8213393607260249141273724587006606315588
1748815209209628292540917153643678925903
6001133053054882046652138414695194151160
9433057270365759591953092186117381932611
7931051185480744623799627495673518857527
2489122793818301194912983367336244065664
3086021394946395224737190702179860943702
7705392171762931767523846748184676694051
3200056812714526356082778577134275778960
9173637178721468440901224953430146549585
3710507922796892589235420199561121290219
6086403441815981362977477130996051870721
1349999998372978049951059731732816096318
5950244594553469083026425223082533446850
3526193118817101000313783875288658753320
8381420617177669147303598253490428755468
7311595628638823537875937519577818577805
3217122680661300192787661119590921642019
89

it is like what you wanted ?

the missing plane at top left is the dot after the first digit = 3

note: let me know if you see any errors !

happy bl

1 Like

here is shown with cube having height = to the pie number

happy bl

1 Like