Convert numbers to RGB

Wow! Nice script @RickyBlender! That’s exactly what I was trying to do. Would you mind sharing how you made it?

i just did a very simple pure python script - it is not optimized at all!
might be possible to do it faster somehow but needs more time to think how to do that !

so if you need to change the parameters it has to be done in the script itself
from the script editor in blender

i did not add any panel or operator in blender !

can you work with that ?

also run script on my small machine takes like 20 seconds for 1000 numbers

if you go higher numbers it will take longer to run it

but i doubt you can go much higher then a few 1000

note :This is done in 2.79 not 2.8

happy bl

how many pi number do you want to go at ?

i ported it to 2.9
but time in 2.79 is like 20 sec for 1000
in 2.9 it takes like 120 sec which is very sluggish indeed

so i’m trying to optimize the script so it runs faster
give me till next monday i will work on it this weekend
hope it can run way faster

happy bl

Here’s the first 128x128x3 digits of Pi converted to RGB values using int(digit/10*256):

PyPic1

Here’s the Python (regular Python rather than from in Blender):

# PiPic.py - Extract picture from Pi
# Change our working directory to somewhere we extracted the Pi digits Zip.
# Change the drive and directory to whatever you're using

import os
os.chdir('G:\pipics')

# Make a new image 128x128 pixels initialized to black

from PIL import Image # Needs Anaconda or pip install pillow
im = Image.new("RGB", (128, 128), (0,0,0))
px = im.load()

# Let's load up 1,000,000 digits of Pi into a string to play with
# Pi Digits downloaded from https://thestarman.pcministry.com/math/pi/picalcs.htm
# Specifically https://thestarman.pcministry.com/math/pi/df/pi1milDS.zip
# which contains the file referenced in the next line:

with open ("PI1MILDS.txt", "r") as myfile:
    data=myfile.readlines()
pi = data[0].replace('\n', '')

# At this point pi is a one million character long string containing the first digits of Pi
# pi[4] is the 5th digit of Pi as a one character string (the first digit is pi[0]).
# px[x,y] is the (r,g,b) value of a pixel, which can be assigned to to change it.
# im is the image itself (for display or saving purposes).

# Function to take a triple-offset into the Pi digits and return an RGB tuple.

def get_pi_tuple(offset):
    r = int(float(pi[offset*3])/10*256)
    g = int(float(pi[offset*3+1])/10*256)
    b = int(float(pi[offset*3+2])/10*256)
    return (r,g,b)

# Now fill our image pixels with Pi!

for y in range(128):
    for x in range(128):
        px[x, y] = get_pi_tuple(y * 128 + x)

# Display the image in the system default image viewer

im.show()

# Save it to a file

im.save("PiPic1.png","PNG")

There are a zillion ways you could change the visualization to use/display the Pi digits differently, change the color mapping, etc.

For fun, here’s 512x512 using the first 786,432 digits:

(Click on the image to see it without scaling)

And here’s that image after feeding it to Blender’s OIDN Denoise Compositing node:

Enjoy!

1 Like

You guys have been really cool. Thanks to @RickyBlender & @Zoot for working on scripts.

I’m amazed at the 512x512 image with 786,432 digits! Your notations were helpful. Thank you so much!

I found a big-eyed cat-looking dude on the red output of the separate RGB node. :smiley:

It’s fun to look for pictures and let your imagination use the random noise of Pi as fuel for thought.

3 Likes

i got a first version of script doing 1000 planes or cubes
inside 0.4 second on my small PC

looking at adding a panel to set the parameters
but wont’ execute if there are any objects in scene
or would overwrite at same location objects.

happy bl

1 Like

1 - keep original file and make a copy to work with

The addon is added in the UI or N panel in the 3D viewport 
under the the Workspace panel

open the file and run the script from the Text editor panel

Note: the time to execute and pie numbers are shown in the console
each number from 0 to 9 has a specific color on the shape

2 - Script works only if the scene is empty

if there is any object you get a first addon window like the following panel


so click on bottom button to clear all objects in scene

3 - After clearing all the objexts in scene
you get the following addon panel

set the number of row and columns 
select shape you want  plane or cube 


then click on bottom button to generate the pie-numbers objects in scene  

4 - a did tests

a ) 1000 objects  added in 0.4 Sec
b ) 10000 objets added in 81 Sec

As you can see the more pie number you want the longer it takes
and it is not proportionel.

Above a 1000 objects in viewport blender is getting sluggish and takes more and more time.
All objects are part of a list and the more items you have in list the longer it takes
to work with.

here is example with 10 000 numbers with colors

pie-pan5.blend (148.4 KB)

have fun with the script
happy bl

1 Like