def getPalette(): colors = g.getcolors() palette = {} for i in xrange( 0, len(colors), 4 ): state = colors[ i ] rVal = colors[ i + 1 ] gVal = colors[ i + 2 ] bVal = colors[ i + 3 ] palette[ state ] = ( rVal, gVal, bVal ) return palette
def getPalette(): colors = g.getcolors() palette = {} for i in xrange(0, len(colors), 4): state = colors[i] rVal = colors[i + 1] gVal = colors[i + 2] bVal = colors[i + 3] palette[state] = (rVal, gVal, bVal) return palette
statecount[g.getcell(col, row)] += 1 newsecs = time() if newsecs - oldsecs >= 1.0: # show % done every sec oldsecs = newsecs done = 100.0 * float(counted) / float(totalcells) g.show("Counting cell states... %.2f%%" % done) g.dokey(g.getkey()) statecount = [int(10 * math.log((x + 1), 2)) for x in statecount] totalcells = sum(statecount) if statecount[0] == counted: g.exit("Selection is empty.") # save current layer's info before we switch layers currname = g.getname() currcursor = g.getcursor() currcolors = g.getcolors() currstates = g.numstates() deads, deadr, deadg, deadb = g.getcolors(0) # create histogram in separate layer g.setoption("stacklayers", 0) g.setoption("tilelayers", 0) g.setoption("showlayerbar", 1) if histlayer == -1: histlayer = g.addlayer() else: g.setlayer(histlayer) g.new(histname) g.setcursor(currcursor)
# Extract icon images in current layer (created by icon-importer.py) # and either create or update the appropriate .rule file. # Author: Andrew Trevorrow ([email protected]), Feb 2013. import golly as g from glife import getminbox, pattern from glife.BuiltinIcons import circles, diamonds, hexagons, triangles import os from tempfile import mkstemp from shutil import move iconcolors = [] # list of (r,g,b) colors used in all icons allcolors = g.getcolors() deadrgb = (allcolors[1], allcolors[2], allcolors[3]) # this flag becomes True only if an icon uses a non-gray color (ignoring deadrgb) multi_color_icons = False # grayscale # ------------------------------------------------------------------------------ def hex2(i): # convert number from 0..255 into 2 hex digits hexdigit = "0123456789ABCDEF" result = hexdigit[i // 16] result += hexdigit[i % 16] return result # --------------------------------------------------------------------
prect = g.getrect() srect = g.getselrect() if len(srect) > 0: prect = srect # save selection rather than pattern x = prect[0] y = prect[1] wd = prect[2] ht = prect[3] # prevent Image.new allocating a huge amount of memory if wd * ht >= 100000000: g.exit("Image area is restricted to < 100 million cells.") # create RGB image filled initially with state 0 color multistate = g.numstates() > 2 colors = g.getcolors() # [0,r0,g0,b0, ... N,rN,gN,bN] g.show("Creating image...") im = Image.new("RGB", (wd, ht), (colors[1], colors[2], colors[3])) # get a row of cells at a time to minimize use of Python memory cellcount = 0 for row in xrange(ht): cells = g.getcells([x, y + row, wd, 1]) clen = len(cells) if clen > 0: inc = 2 if multistate: # cells is multi-state list (clen is odd) inc = 3 if clen % 3 > 0: clen -= 1 # ignore last 0 for i in xrange(0, clen, inc):
# the icons in that file sharedname = check_for_shared_rule(rulename) if len(sharedname) > 0: rulename = sharedname import_icons(rulename) iconnote = "" if len(iconcolors) == 0: iconnote = "There are currently no icons for this rule.\n\n" # check if icons are grayscale grayscale_icons = not multi_color_icons(iconcolors) g.new(layerprefix + rulename) livestates = g.numstates() - 1 deadcolor = g.getcolors(0) deadrgb = (deadcolor[1], deadcolor[2], deadcolor[3]) # switch to a Generations rule so we can have lots of colors g.setrule("//256") if grayscale_icons and deadrgb == (255,255,255): # if icons are grayscale and state 0 color was white then switch # to black background to avoid confusion (ie. we want black pixels # to be transparent) g.setcolors([0,0,0,0]) else: g.setcolors(deadcolor) graystate = init_colors() # if icons are grayscale then change deadrgb to black so that draw_icons # will treat black pixels as transparent
prect = g.getrect() srect = g.getselrect() if len(srect) > 0: prect = srect # save selection rather than pattern x = prect[0] y = prect[1] wd = prect[2] ht = prect[3] # prevent Image.new allocating a huge amount of memory if wd * ht >= 100000000: g.exit("Image area is restricted to < 100 million cells.") # create RGB image filled initially with state 0 color multistate = g.numstates() > 2 colors = g.getcolors() # [0,r0,g0,b0, ... N,rN,gN,bN] g.show("Creating image...") im = Image.new("RGB", (wd,ht), (colors[1],colors[2],colors[3])) # get a row of cells at a time to minimize use of Python memory cellcount = 0 for row in xrange(ht): cells = g.getcells( [ x, y + row, wd, 1 ] ) clen = len(cells) if clen > 0: inc = 2 if multistate: # cells is multi-state list (clen is odd) inc = 3 if clen % 3 > 0: clen -= 1 # ignore last 0 for i in xrange(0, clen, inc):
# Extract icon images in current layer (created by icon-importer.py) # and either create or update the appropriate .rule file. # Author: Andrew Trevorrow ([email protected]), Feb 2013. import golly as g from glife import getminbox, pattern from glife.BuiltinIcons import circles, diamonds, hexagons, triangles import os from tempfile import mkstemp from shutil import move iconcolors = [] # list of (r,g,b) colors used in all icons allcolors = g.getcolors() deadrgb = (allcolors[1], allcolors[2], allcolors[3]) # this flag becomes True only if an icon uses a non-gray color (ignoring deadrgb) multi_color_icons = False # grayscale # ------------------------------------------------------------------------------ def hex2(i): # convert number from 0..255 into 2 hex digits hexdigit = "0123456789ABCDEF" result = hexdigit[i / 16] result += hexdigit[i % 16] return result # -------------------------------------------------------------------- def extract_icons(iconsize):
# the icons in that file sharedname = check_for_shared_rule(rulename) if len(sharedname) > 0: rulename = sharedname import_icons(rulename) iconnote = "" if len(iconcolors) == 0: iconnote = "There are currently no icons for this rule.\n\n" # check if icons are grayscale grayscale_icons = not multi_color_icons(iconcolors) g.new(layerprefix + rulename) livestates = g.numstates() - 1 deadcolor = g.getcolors(0) deadrgb = (deadcolor[1], deadcolor[2], deadcolor[3]) # switch to a Generations rule so we can have lots of colors g.setrule("//256") if grayscale_icons and deadrgb == (255, 255, 255): # if icons are grayscale and state 0 color was white then switch # to black background to avoid confusion (ie. we want black pixels # to be transparent) g.setcolors([0, 0, 0, 0]) else: g.setcolors(deadcolor) graystate = init_colors() # if icons are grayscale then change deadrgb to black so that draw_icons # will treat black pixels as transparent