def setstatecolors(self, state, r, gr, b):
     """
     Sets the color of the specified state
     :param state: the color state to be changed
     :param r: the red value
     :param gr: the green value
     :param b: the blue value
     """
     g.setcolors([state, r, gr, b])
예제 #2
0
# use a Generations rule so we can append extra state for drawing text & lines
g.setrule("//" + str(currstates + 1))
extrastate = currstates
currcolors.append(extrastate)
if (deadr + deadg + deadb) / 3 > 128:
    # use black if light background
    currcolors.append(0)
    currcolors.append(0)
    currcolors.append(0)
else:
    # use white if dark background
    currcolors.append(255)
    currcolors.append(255)
    currcolors.append(255)
g.setcolors(currcolors)

# draw axes with origin at 0,0
draw_line(0, 0, xlen, 0, extrastate)
draw_line(0, 0, 0, -ylen, extrastate)

# add annotation using mono-spaced ASCII font
t, twd, tht = color_text("Pattern name: " + currname, extrastate)
t.put(0, -ylen - 30 - tht)

t, twd, tht = color_text(
    "%s size: %d x %d (%d cells)" % (label, r.wd, r.ht, totalcells),
    extrastate)
t.put(0, -ylen - 15 - tht)

t, twd, tht = color_text("% FREQUENCY", extrastate)
예제 #3
0
# Peter Turney, August 9, 2020
#
# Load a seed from a pickle and display it
# in Golly.
#
import golly as g
import model_classes as mclass
import model_functions as mfunc
import model_parameters as mparam
import pickle
#
# Set the colours so they are suitable for printing.
# The background should be light and the foreground
# should be dark.
#
g.setcolors([0, 255, 255, 255, 1, 0, 0, 0])
#
# Ask the user to select a pickle.
#
g.note("You will be asked to select a pickled seed file.\n" + \
       "The top seed in the file will be inserted into Golly.")
#
pickle_path = g.opendialog("Select a pickled seed file (*.bin)", \
  "(*.bin)|*.bin", g.getdir("app"))
#
# Read the pickle file.
#
pickle_handle = open(pickle_path, "rb")  # rb = read binary
pickle = pickle.load(pickle_handle)
pickle_handle.close()
#
 def set_border_color(self, fief):
     """
     Sets the selected grid to the color assisgned to the fief
     :param fief: The fief that has already been assigned a color
     """
     g.setcolors([fief.color_number, fief.red, fief.green, fief.blue])
예제 #5
0
            g.setlayer(poplayer)

        if poplayer == -1:
            poplayer = g.addlayer()
        else:
            g.setlayer(poplayer)
        plotlayer = g.getlayer()
        g.new(layername)
        g.setrule('Life')
        # use same rule but without any suffix (we don't want a bounded grid)
        # g.setrule(g.getrule().split(":")[0])

        deadr, deadg, deadb = g.getcolor("deadcells")
        if (deadr + deadg + deadb) / 3 > 128:
            # use black if light background
            g.setcolors([1, 0, 0, 0])
        else:
            # use white if dark background
            g.setcolors([1, 255, 255, 255])

        minpop = min(poplist)
        maxpop = max(poplist)
        if minpop == maxpop:
            # avoid division by zero
            minpop -= 1

        # popscale=g.getstring('what scale to use for pop/y?','%i'%int((maxpop-minpop)/100))
        popscale = 1
        popscale = int(popscale)
        mingen = min(genlist)
        maxgen = max(genlist)
예제 #6
0
    g.setlayer(currindex)
    startindex = currindex - 1
    envindex = currindex - 2

else:
    # start a new envelope using pattern in current layer
    if g.numlayers() + 1 > g.maxlayers():
        g.exit("You need to delete a couple of layers.")
    if g.numlayers() + 2 > g.maxlayers():
        g.exit("You need to delete a layer.")

    # get current layer's starting pattern
    startpatt = g.getcells(g.getrect())

    envindex = g.addlayer()       # create layer for remembering all live cells
    g.setcolors([-1,100,100,100]) # set all states to darkish gray
    g.putcells(startpatt)         # copy starting pattern into this layer

    startindex = g.addlayer()     # create layer for starting pattern
    g.setcolors([-1,0,255,0])     # set all states to green
    g.putcells(startpatt)         # copy starting pattern into this layer

    # move currindex to above the envelope and starting pattern
    g.movelayer(currindex, envindex)
    g.movelayer(envindex, startindex)
    currindex = startindex
    startindex = currindex - 1
    envindex = currindex - 2

    # name the starting and envelope layers so user can run script
    # again and continue from where it was stopped
예제 #7
0
def init_colors():
    global iconcolors, colorstate
    if len(iconcolors) > 240: g.exit("The imported icons use too many colors!")
    
    # start with gradient from white to black (this makes it easier to
    # copy grayscale icons from one rule to another rule)
    s = 1
    g.setcolors([s,255,255,255])
    colorstate[(255,255,255)] = s
    s += 1
    graylevel = 256
    while graylevel > 0:
        graylevel -= 32
        g.setcolors([s, graylevel, graylevel, graylevel])
        colorstate[(graylevel, graylevel, graylevel)] = s
        s += 1

    # now add all the colors used in the imported icons (unless added above)
    for rgb in iconcolors:
        if not rgb in colorstate:
            R,G,B = rgb
            g.setcolors([s,R,G,B])
            colorstate[rgb] = s
            s += 1
    
    # finally add rainbow colors in various shades (bright, pale, dark)
    for hue in xrange(12):
        if s > 255: break
        R,G,B = hsv_to_rgb(hue/12.0, 1.0, 1.0)
        g.setcolors([s, int(255*R), int(255*G), int(255*B)])
        s += 1
    for hue in xrange(12):
        if s > 255: break
        R,G,B = hsv_to_rgb(hue/12.0, 0.5, 1.0)
        g.setcolors([s, int(255*R), int(255*G), int(255*B)])
        s += 1
    for hue in xrange(12):
        if s > 255: break
        R,G,B = hsv_to_rgb(hue/12.0, 1.0, 0.5)
        g.setcolors([s, int(255*R), int(255*G), int(255*B)])
        s += 1
    
    # return the 50% gray state (used for drawing boxes and text)
    return colorstate[(128,128,128)]
 s2.red2blue()
 # set up Golly
 [g_width, g_height, g_time] = mfunc.dimensions(s1, s2, \
     width_factor, height_factor, time_factor)
 g.setalgo("QuickLife")  # use the QuickLife algorithm
 g.new("Immigration")  # initialize cells to state 0
 g.setrule("Immigration:T" + str(g_width) + "," +
           str(g_height))  # make a toroid
 [g_xmin, g_xmax, g_ymin,
  g_ymax] = mfunc.get_minmax(g)  # find range of coordinates
 s1.insert(g, g_xmin, -1, g_ymin,
           g_ymax)  # insert the first seed into Golly
 s2.insert(g, +1, g_xmax, g_ymin,
           g_ymax)  # insert the second seed into Golly
 g.setmag(mfunc.set_mag(g))  # set magnification
 g.setcolors([0, 255, 255, 255])  # set state 0 (the background) to white
 #
 g.update()  # show the intial state
 #
 g.note("These are the intial seeds.\n" + \
   "Red is on the left and blue is on the right.\n" + \
   "The file names are in the header of the main window.\n" + \
   "Drag this note to a new location if it is blocking your view.\n\n" + \
   "Red seed directory:  " + head1 + "\n" + \
   "Red seed file:  " + tail1 + "\n" + \
   "Red seed size:  {} x {}\n".format(seed1.xspan, seed1.yspan) + \
   "Red seed density:  {:.4f} ({} ones)\n\n".format(seed1.density(), \
     seed1.count_ones()) + \
   "Blue seed directory: " + head2 + "\n" + \
   "Blue seed file: " + tail2 + "\n" + \
   "Blue seed size: {} x {}\n".format(seed2.xspan, seed2.yspan) + \
예제 #9
0
# 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
if grayscale_icons: deadrgb = (0,0,0)

draw_icon_boxes(livestates, graystate)
draw_icons(iconinfo31, deadrgb)
draw_icons(iconinfo15, deadrgb)
draw_icons(iconinfo7, deadrgb)

# create missing icons by scaling up/down the existing icons
if len(iconinfo31) == 0 and len(iconinfo15) > 0:
예제 #10
0
g.setoption("stacklayers", 0)
g.setoption("tilelayers", 0)
g.setoption("showlayerbar", 1)
if poplayer == -1:
    poplayer = g.addlayer()
else:
    g.setlayer(poplayer)
g.new(layername)

# use same rule but without any suffix (we don't want a bounded grid)
g.setrule(g.getrule().split(":")[0])

deadr, deadg, deadb = g.getcolor("deadcells")
if (deadr + deadg + deadb) / 3 > 128:
    # use black if light background
    g.setcolors([1,0,0,0])
else:
    # use white if dark background
    g.setcolors([1,255,255,255])

minpop = min(poplist)
maxpop = max(poplist)
if minpop == maxpop:
    # avoid division by zero
    minpop -= 1
popscale = float(maxpop - minpop) / float(ylen)

mingen = min(genlist)
maxgen = max(genlist)
genscale = float(maxgen - mingen) / float(xlen)
예제 #11
0
    g.setlayer(currindex)
    startindex = currindex - 1
    envindex = currindex - 2

else:
    # start a new envelope using pattern in current layer
    if g.numlayers() + 1 > g.maxlayers():
        g.exit("You need to delete a couple of layers.")
    if g.numlayers() + 2 > g.maxlayers():
        g.exit("You need to delete a layer.")

    # get current layer's starting pattern
    startpatt = g.getcells(g.getrect())

    envindex = g.addlayer()  # create layer for remembering all live cells
    g.setcolors([-1, 100, 100, 100])  # set all states to darkish gray
    g.putcells(startpatt)  # copy starting pattern into this layer

    startindex = g.addlayer()  # create layer for starting pattern
    g.setcolors([-1, 0, 255, 0])  # set all states to green
    g.putcells(startpatt)  # copy starting pattern into this layer

    # move currindex to above the envelope and starting pattern
    g.movelayer(currindex, envindex)
    g.movelayer(envindex, startindex)
    currindex = startindex
    startindex = currindex - 1
    envindex = currindex - 2

    # name the starting and envelope layers so user can run script
    # again and continue from where it was stopped
예제 #12
0
def init_colors():
    global iconcolors, colorstate
    if len(iconcolors) > 240: g.exit("The imported icons use too many colors!")

    # start with gradient from white to black (this makes it easier to
    # copy grayscale icons from one rule to another rule)
    s = 1
    g.setcolors([s, 255, 255, 255])
    colorstate[(255, 255, 255)] = s
    s += 1
    graylevel = 256
    while graylevel > 0:
        graylevel -= 32
        g.setcolors([s, graylevel, graylevel, graylevel])
        colorstate[(graylevel, graylevel, graylevel)] = s
        s += 1

    # now add all the colors used in the imported icons (unless added above)
    for rgb in iconcolors:
        if not rgb in colorstate:
            R, G, B = rgb
            g.setcolors([s, R, G, B])
            colorstate[rgb] = s
            s += 1

    # finally add rainbow colors in various shades (bright, pale, dark)
    for hue in range(12):
        if s > 255: break
        R, G, B = hsv_to_rgb(hue / 12.0, 1.0, 1.0)
        g.setcolors([s, int(255 * R), int(255 * G), int(255 * B)])
        s += 1
    for hue in range(12):
        if s > 255: break
        R, G, B = hsv_to_rgb(hue / 12.0, 0.5, 1.0)
        g.setcolors([s, int(255 * R), int(255 * G), int(255 * B)])
        s += 1
    for hue in range(12):
        if s > 255: break
        R, G, B = hsv_to_rgb(hue / 12.0, 1.0, 0.5)
        g.setcolors([s, int(255 * R), int(255 * G), int(255 * B)])
        s += 1

    # return the 50% gray state (used for drawing boxes and text)
    return colorstate[(128, 128, 128)]
예제 #13
0
# 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
if grayscale_icons: deadrgb = (0, 0, 0)

draw_icon_boxes(livestates, graystate)
draw_icons(iconinfo31, deadrgb)
draw_icons(iconinfo15, deadrgb)
draw_icons(iconinfo7, deadrgb)

# create missing icons by scaling up/down the existing icons
if len(iconinfo31) == 0 and len(iconinfo15) > 0: