コード例 #1
0
ファイル: draw-lines.py プロジェクト: Nesk8er/WebLife1
            if started and len(mousepos) == 0:
                # erase old line if mouse is not over grid
                if len(oldline) > 0:
                    eraseline(oldline)
                    oldline = []
                    g.update()
            elif started and len(mousepos) > 0 and mousepos != oldmouse:
                # mouse has moved, so erase old line (if any) and draw new line
                if len(oldline) > 0: eraseline(oldline)
                x, y = mousepos.split()
                oldline = drawline(startx, starty, int(x), int(y))
                oldmouse = mousepos

# ------------------------------------------------------------------------------

g.show("Click where to start line...")
oldcursor = g.getcursor()
g.setcursor("Draw")
drawstate = g.getoption("drawingstate")
oldline = []
firstcell = []    # pos and state of the 1st cell clicked

try:
    drawlines()
finally:
    g.setcursor(oldcursor)
    if len(oldline) > 0: eraseline(oldline)
    if len(firstcell) > 0:
        x, y, s = firstcell
        g.setcell(x, y, s)
コード例 #2
0
        counted += 1
        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)
コード例 #3
0
ファイル: move-selection.py プロジェクト: mp-lee/golly
            g.putcells(selpatt, x - firstx, y - firsty)
            oldmouse = mousepos
            g.update()

# ------------------------------------------------------------------------------

selrect = g.getselrect()
if len(selrect) == 0: g.exit("There is no selection.")
selpatt = g.getcells(selrect)

# remember initial selection in case user aborts script
firstrect = g.getselrect()
firstpatt = g.getcells(selrect)

g.show("Click anywhere in selection, move mouse and click again..." + helpmsg)
oldcursor = g.getcursor()
g.setcursor("Move")
oldcells = []

try:
    aborted = True
    moveselection()
    aborted = False
finally:
    g.setcursor(oldcursor)
    if aborted:
        g.clear(0)
        if len(oldcells) > 0: g.putcells(oldcells)
        g.putcells(firstpatt)
        g.select(firstrect)
    else: