Musings of a Fondue

Image sources:

I used this simple Python script to generate the bead patterns. I hope to eventually turn it into a GIMP plugin.

``````
from PIL import Image
from math import ceil
from operator import itemgetter

'''
Generates a bead count and pattern from a given image.
To use, call 'generatePattern' with the image path as an argument.
'''

# __ Functions _______________________________________________________________

def rgb2hex ( c ):

r = hex( c[ 0 ] )[ 2: ].zfill( 2 )
g = hex( c[ 1 ] )[ 2: ].zfill( 2 )
b = hex( c[ 2 ] )[ 2: ].zfill( 2 )

return '{}{}{}'.format( r, g, b )

def countPixels ( imagePalette, beadsPerVial ):

totalVials  = 0
totalPixels = 0

print( '{:<10} {:<10} {:<9} {}'.format( "count", "vials", "color", "index" ) )
print( '-----      -----      ------    -----' )

i = 0

for color in imagePalette:

count = color[ 0 ]

nVials = ceil( count / beadsPerVial )

print( '{:<10} {:<10} {:<9} {}'.format(

count,
nVials,
rgb2hex( color[ 1 ] ),
hex( i ) [ 2: ]
) )

totalPixels += count
totalVials  += nVials
i     += 1

print()
print( 'Grand total = {} beads, approx {} vials\n\n'.format( totalPixels, totalVials ) )

def genAscii ( image, imagePalette ):

w, h = image.size

line = ''
j    = 0

for pixel in image.getdata():

for i in range( len( imagePalette ) ):

if pixel == imagePalette[ i ][ 1 ]:

line += hex( i )[ 2: ]

break
j += 1

if j % w == 0:  # a row

print( line )

line = ''

def generatePattern ( imagePath, beadsPerVial = 2500 ):

# Get the image
image = Image.open( imagePath )
image = image.convert( 'RGBA' )

# Get image palette
imagePalette = image.getcolors()

# Sort palette by count
imagePalette = sorted( imagePalette, key = itemgetter( 0 ), reverse = True )

# Approximate number of vials needed for each color