Ejemplo n.º 1
0
def gofast(newgen, delay):
   ''' Fast goto '''
   #Save current settings
   oldbase = g.getbase()
   # oldhash = g.setoption("hashing", True)
   
   g.show('gofast running, hit escape to abort')
   oldsecs = time()
   
   #Advance by binary powers, to maximize advantage of hashing
   g.setbase(2)
   for i, b in enumerate(intbits(newgen)):
      if b:
         g.setstep(i)
         g.step()
         g.dokey(g.getkey())
         newsecs = time()
         if newsecs - oldsecs >= delay:  # do an update every sec
            oldsecs = newsecs
            g.update()
         if   g.empty():
            break
   
   g.show('')
   
   #Restore settings
   # g.setoption("hashing", oldhash)
   g.setbase(oldbase)
Ejemplo n.º 2
0
def envelope ():
    # draw stacked layers using same location and scale
    g.setoption("stacklayers", 1)

    g.show("Hit escape key to stop script...")
    while True:
        g.run(1)
        if g.empty():
            g.show("Pattern died out.")
            break

        # copy current pattern to envelope layer;
        # we temporarily disable event checking so thumb scrolling
        # and other mouse events won't cause confusing changes
        currpatt = g.getcells(g.getrect())
        g.check(0)
        g.setlayer(envindex)
        g.putcells(currpatt)
        g.setlayer(currindex)
        g.check(1)

        step = 1
        exp = g.getstep()
        if exp > 0:
            step = g.getbase()**exp
        if int(g.getgen()) % step == 0:
            # display all 3 layers (envelope, start, current)
            g.update()
Ejemplo n.º 3
0
def envelope():
    # draw stacked layers using same location and scale
    g.setoption("stacklayers", 1)

    g.show("Hit escape key to stop script...")
    while True:
        g.run(1)
        if g.empty():
            g.show("Pattern died out.")
            break

        # copy current pattern to envelope layer;
        # we temporarily disable event checking so thumb scrolling
        # and other mouse events won't cause confusing changes
        currpatt = g.getcells(g.getrect())
        g.check(0)
        g.setlayer(envindex)
        g.putcells(currpatt)
        g.setlayer(currindex)
        g.check(1)

        step = 1
        exp = g.getstep()
        if exp > 0:
            step = g.getbase()**exp
        if int(g.getgen()) % step == 0:
            # display all 3 layers (envelope, start, current)
            g.update()
Ejemplo n.º 4
0
def goto(newgen, delay):
   g.show("goto running, hit escape to abort...")
   oldsecs = time()
   
   # before stepping we advance by 1 generation, for two reasons:
   # 1. if we're at the starting gen then the *current* step size
   #    will be saved (and restored upon Reset/Undo) rather than a
   #    possibly very large step size
   # 2. it increases the chances the user will see updates and so
   #    get some idea of how long the script will take to finish
   #    (otherwise if the base is 10 and a gen like 1,000,000,000
   #    is given then only a single step() of 10^9 would be done)
   if delay <= 1.0:
     g.run(1)
     newgen -= 1
   
   # use fast stepping (thanks to PM 2Ring)
   for i, d in enumerate(intbase(newgen, g.getbase())):
      if d > 0:
         g.setstep(i)
         for j in xrange(d):
            if g.empty():
               g.show("Pattern is empty.")
               return
            g.step()
            newsecs = time()
            if newsecs - oldsecs >= delay:  # time to do an update?
               oldsecs = newsecs
               g.update()
   g.show("")
Ejemplo n.º 5
0
def gofast(newgen, delay):
    ''' Fast goto '''
    #Save current settings
    oldbase = g.getbase()
    # oldhash = g.setoption("hashing", True)

    g.show('gofast running, hit escape to abort')
    oldsecs = time()

    #Advance by binary powers, to maximize advantage of hashing
    g.setbase(2)
    for i, b in enumerate(intbits(newgen)):
        if b:
            g.setstep(i)
            g.step()
            g.dokey(g.getkey())
            newsecs = time()
            if newsecs - oldsecs >= delay:  # do an update every sec
                oldsecs = newsecs
                g.update()
            if g.empty():
                break

    g.show('')

    #Restore settings
    # g.setoption("hashing", oldhash)
    g.setbase(oldbase)
Ejemplo n.º 6
0
def goto(newgen, delay):
    g.show("goto running, hit escape to abort...")
    oldsecs = time()

    # before stepping we advance by 1 generation, for two reasons:
    # 1. if we're at the starting gen then the *current* step size
    #    will be saved (and restored upon Reset/Undo) rather than a
    #    possibly very large step size
    # 2. it increases the chances the user will see updates and so
    #    get some idea of how long the script will take to finish
    #    (otherwise if the base is 10 and a gen like 1,000,000,000
    #    is given then only a single step() of 10^9 would be done)
    if delay <= 1.0:
        g.run(1)
        newgen -= 1

    # use fast stepping (thanks to PM 2Ring)
    for i, d in enumerate(intbase(newgen, g.getbase())):
        if d > 0:
            g.setstep(i)
            for j in range(d):
                if g.empty():
                    g.show("Pattern is empty.")
                    return
                g.step()
                newsecs = time()
                if newsecs - oldsecs >= delay:  # time to do an update?
                    oldsecs = newsecs
                    g.update()
    g.show("")
Ejemplo n.º 7
0
def GotoLimited(gen, power):
    g.setbase(8)
    g.setstep(power)

    while gen > int(g.getgen()) + g.getbase()**power:
        g.step()
        g.update()

    goto(gen)
Ejemplo n.º 8
0
def GotoLimited(gen, power):
	g.setbase(8)
	g.setstep(power)

	while gen > int(g.getgen()) + g.getbase()**power:
		g.step()
		g.update()
		
	goto(gen)
Ejemplo n.º 9
0
def goto(newgen):
    currgen = int(g.getgen())
    
    if newgen < currgen:
        # try to go back to starting gen (not necessarily 0) and
        # then forwards to newgen; note that reset() also restores
        # algorithm and/or rule, so too bad if user changed those
        # after the starting info was saved;
        # first save current location and scale
        midx, midy = g.getpos()
        mag = g.getmag()
        g.reset()
        # restore location and scale
        g.setpos(midx, midy)
        g.setmag(mag)
        # current gen might be > 0 if user loaded a pattern file
        # that set the gen count
        currgen = int(g.getgen())
        if newgen < currgen:
            g.error("Can't go back any further; pattern was saved " +
                    "at generation " + str(currgen) + ".")
            return
    if newgen == currgen: return

    oldsecs = time()

    # before stepping we advance by 1 generation, for two reasons:
    # 1. if we're at the starting gen then the *current* step size
    #    will be saved (and restored upon Reset/Undo) rather than a
    #    possibly very large step size
    # 2. it increases the chances the user will see updates and so
    #    get some idea of how long the script will take to finish
    #    (otherwise if the base is 10 and a gen like 1,000,000,000
    #    is given then only a single step() of 10^9 would be done)
    g.run(1)
    currgen += 1

    # use fast stepping (thanks to PM 2Ring)
    oldstep = g.getstep()
    for i, d in enumerate(intbase(newgen - currgen, g.getbase())):
        if d > 0:
            g.setstep(i)
            for j in xrange(d):
                if g.empty():
                    g.show("Pattern is empty.")
                    return
                g.step()
                newsecs = time()
                if newsecs - oldsecs >= 1.0:  # do an update every sec
                    oldsecs = newsecs
                    g.update()
    g.setstep(oldstep)
Ejemplo n.º 10
0
def goto(newgen):
    currgen = int(g.getgen())

    if newgen < currgen:
        # try to go back to starting gen (not necessarily 0) and
        # then forwards to newgen; note that reset() also restores
        # algorithm and/or rule, so too bad if user changed those
        # after the starting info was saved;
        # first save current location and scale
        midx, midy = g.getpos()
        mag = g.getmag()
        g.reset()
        # restore location and scale
        g.setpos(midx, midy)
        g.setmag(mag)
        # current gen might be > 0 if user loaded a pattern file
        # that set the gen count
        currgen = int(g.getgen())
        if newgen < currgen:
            g.error("Can't go back any further; pattern was saved " +
                    "at generation " + str(currgen) + ".")
            return
    if newgen == currgen: return

    oldsecs = time()

    # before stepping we advance by 1 generation, for two reasons:
    # 1. if we're at the starting gen then the *current* step size
    #    will be saved (and restored upon Reset/Undo) rather than a
    #    possibly very large step size
    # 2. it increases the chances the user will see updates and so
    #    get some idea of how long the script will take to finish
    #    (otherwise if the base is 10 and a gen like 1,000,000,000
    #    is given then only a single step() of 10^9 would be done)
    g.run(1)
    currgen += 1

    # use fast stepping (thanks to PM 2Ring)
    oldstep = g.getstep()
    for i, d in enumerate(intbase(newgen - currgen, g.getbase())):
        if d > 0:
            g.setstep(i)
            for j in xrange(d):
                if g.empty():
                    g.show("Pattern is empty.")
                    return
                g.step()
                newsecs = time()
                if newsecs - oldsecs >= 1.0:  # do an update every sec
                    oldsecs = newsecs
                    g.update()
    g.setstep(oldstep)
Ejemplo n.º 11
0
            g.show("Step %i of %i, Topo %i" % (i + 1, numsteps, posi))

            event = g.getevent()
            if event.startswith("key"):
                evt, ch, mods = event.split()
                if ch == "q":
                    out = 1
                    numsteps = i
                    break

        fit_if_not_visible()

        # poplist.sort(key=dict(zip(poplist, genlist)).get)

        # save some info before we switch layers
        stepsize = "%i^%i" % (g.getbase(), g.getstep())
        pattname = g.getname()

        # create population plot in separate layer
        g.setoption("stacklayers", 0)
        g.setoption("tilelayers", 0)
        g.setoption("showlayerbar", 1)

        layername = "population plot"
        poplayer = -1
        for i in xrange(g.numlayers()):
            if g.getname(i) == layername:
                poplayer = i
                break
        if poplayer == -1 and g.numlayers() == g.maxlayers():
            g.exit("You need to delete a layer.")
Ejemplo n.º 12
0
oldsecs = time()
for i in xrange(numsteps):
    g.step()
    poplist.append( int(g.getpop()) )
    genlist.append( int(g.getgen()) )
    newsecs = time()
    if newsecs - oldsecs >= 1.0:     # show pattern every second
        oldsecs = newsecs
        fit_if_not_visible()
        g.update()
        g.show("Step %i of %i" % (i+1, numsteps))

fit_if_not_visible()

# save some info before we switch layers
stepsize = "%i^%i" % (g.getbase(), g.getstep())
pattname = g.getname()

# create population plot in separate layer
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])