def lookforkeys(event, deltax, deltay):
   global oldcells, selrect, selpatt
   
   # look for keys used to flip/rotate selection
   if event == "key x none" or event == "key y none":
      # flip floating selection left-right or top-bottom
      if len(oldcells) > 0:
         g.clear(0)
         g.putcells(selpatt, deltax, deltay)
      if " x " in event:
         g.flip(0)
      else:
         g.flip(1)
      selpatt = g.transform(g.getcells(selrect), -deltax, -deltay)
      if len(oldcells) > 0:
         g.clear(0)
         g.putcells(oldcells)
         g.putcells(selpatt, deltax, deltay)
      g.update()
      return
   
   if event == "key > none" or event == "key < none":
      # rotate floating selection clockwise or anticlockwise;
      # because we use g.rotate below we have to use the exact same
      # calculation (see Selection::Rotate in wxselect.cpp) for rotrect:
      midx = selrect[0] + int((selrect[2]-1)/2)
      midy = selrect[1] + int((selrect[3]-1)/2)
      newleft = midx + selrect[1] - midy
      newtop = midy + selrect[0] - midx
      rotrect = [ newleft, newtop, selrect[3], selrect[2] ]
      if not rectingrid(rotrect):
         g.warn("Rotation is not allowed if selection would be outside grid.")
         return
      g.clear(0)
      if len(oldcells) > 0: g.putcells(oldcells)
      oldcells = g.join(oldcells, g.getcells(rotrect))
      g.clear(0)
      g.select(rotrect)
      g.clear(0)
      g.select(selrect)
      g.putcells(selpatt, deltax, deltay)
      if " > " in event:
         g.rotate(0)
      else:
         g.rotate(1)
      selrect = g.getselrect()
      if selrect != rotrect: g.warn("Bug: selrect != rotrect")
      selpatt = g.transform(g.getcells(selrect), -deltax, -deltay)
      if len(oldcells) > 0:
         g.clear(0)
         g.putcells(oldcells)
         g.putcells(selpatt, deltax, deltay)
      g.update()
      return

   if event == "key h none":
      showhelp2()
      return
   
   g.doevent(event)
Esempio n. 2
0
def makerecipe(recipe):
  clist = gliderlist[0]
  totaltime=0
  for i in recipe[1:]:
    totaltime+=i
    clist=g.join(clist,g.transform(gliderlist[totaltime%4],totaltime/4,totaltime/4))
  return clist
Esempio n. 3
0
def lookforkeys(event, deltax, deltay):
    global oldcells, selrect, selpatt

    # look for keys used to flip/rotate selection
    if event == "key x none" or event == "key y none":
        # flip floating selection left-right or top-bottom
        if len(oldcells) > 0:
            g.clear(0)
            g.putcells(selpatt, deltax, deltay)
        if " x " in event:
            g.flip(0)
        else:
            g.flip(1)
        selpatt = g.transform(g.getcells(selrect), -deltax, -deltay)
        if len(oldcells) > 0:
            g.clear(0)
            g.putcells(oldcells)
            g.putcells(selpatt, deltax, deltay)
        g.update()
        return

    if event == "key > none" or event == "key < none":
        # rotate floating selection clockwise or anticlockwise;
        # because we use g.rotate below we have to use the exact same
        # calculation (see Selection::Rotate in wxselect.cpp) for rotrect:
        midx = selrect[0] + int((selrect[2]-1)/2)
        midy = selrect[1] + int((selrect[3]-1)/2)
        newleft = midx + selrect[1] - midy
        newtop = midy + selrect[0] - midx
        rotrect = [ newleft, newtop, selrect[3], selrect[2] ]
        if not rectingrid(rotrect):
            g.warn("Rotation is not allowed if selection would be outside grid.")
            return
        g.clear(0)
        if len(oldcells) > 0: g.putcells(oldcells)
        oldcells = g.join(oldcells, g.getcells(rotrect))
        g.clear(0)
        g.select(rotrect)
        g.clear(0)
        g.select(selrect)
        g.putcells(selpatt, deltax, deltay)
        if " > " in event:
            g.rotate(0)
        else:
            g.rotate(1)
        selrect = g.getselrect()
        if selrect != rotrect: g.warn("Bug: selrect != rotrect")
        selpatt = g.transform(g.getcells(selrect), -deltax, -deltay)
        if len(oldcells) > 0:
            g.clear(0)
            g.putcells(oldcells)
            g.putcells(selpatt, deltax, deltay)
        g.update()
        return

    if event == "key h none":
        showhelp2()
        return

    g.doevent(event)
Esempio n. 4
0
def parsefreq(freq):
    '''Get the frequency and convert it to glife.pattern.'''
    # Format string and convert it to cell list.
    pat = list(make_text('{:.3f}'.format(freq), font='mono'))
    # Convert one-state cell list to multi-state cell list
    pat = g.join(pat, [0])
    # Set cell state to state 4
    for idx in xrange(2, len(pat), 3):
        pat[idx] = 4
    return glife.pattern(pat)
Esempio n. 5
0
def parsename(name):
    '''Get the catalyst name and convert it to glife.pattern.'''
    # Convert the string to cell list.
    pat = list(make_text(name, font='mono'))
    # Convert one-state cell list to multi-state cell list
    pat = g.join(pat, [0])
    # Set cell state to state 4
    for idx in xrange(2, len(pat), 3):
        pat[idx] = 4
    return glife.pattern(pat)
Esempio n. 6
0
  parity=1 if s[0]=="O" else 0
  input+=[[int(s[1:]),parity]]
for i,p in input:
  if elbowloc%2==0: # which recipe to use depends on current elbow chirality
    targetlane = i
  else:
    targetlane = -i
  if elbowloc<-48: # -32 doesn't work for the end of the recipe
    move,recipe,parity = posdict[targetlane]
  else:
    move,recipe,parity = negdict[targetlane]
  elbowloc+=move
  adjustedrecipe = recipe[2:] # skip the initial "0"
#  g.note(str([targetlane, move, recipe, parity]))
  if (total+parity+p)%2==1:
    # change the last number in the previous recipe, to flip the parity of the current recipe
    output[-1]+=1
    total+=1
  # now add the current recipe to the total
  for s in adjustedrecipe.split(","): total+=int(s)

  output+=eval("["+adjustedrecipe+"]")
 
# build the resulting recipe and display in a new layer
 
g.setclipstr(str(output).replace("["," ").replace("]","").replace(" ",""))
pat=makerecipe(output[:-1])
g.addlayer()
g.putcells(g.join(elbow,g.transform(pat,5,2)))
g.setalgo("HashLife")
Esempio n. 7
0
 def __add__(self, q):
    """Join patterns."""
    return pattern(golly.join(self, q))
Esempio n. 8
0
 def __add__(self, q):
     """Join patterns."""
     return pattern(golly.join(self, q))