File: make-torus.py

package info (click to toggle)
golly 3.2-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 19,516 kB
  • sloc: cpp: 69,819; ansic: 25,894; python: 7,921; sh: 4,267; objc: 3,721; java: 2,781; xml: 1,362; makefile: 530; perl: 69
file content (29 lines) | stat: -rw-r--r-- 726 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Use the current selection to create a toroidal universe.
# Author: Andrew Trevorrow (andrew@trevorrow.com), Sept 2010.

from glife import inside, outside
import golly as g

selrect = g.getselrect()
if len(selrect) == 0: g.exit("There is no selection.")
x =  selrect[0]
y =  selrect[1]
wd = selrect[2]
ht = selrect[3]

selcells = g.getcells(selrect)
if not g.empty():
    g.clear(inside)
    g.clear(outside)

# get current rule, remove any existing suffix, then add new suffix
rule = g.getrule().split(":")[0]
g.setrule(rule + ":T" + str(wd) + "," + str(ht))

newx = -int(wd/2)
newy = -int(ht/2)
selrect[0] = newx
selrect[1] = newy
g.select(selrect)
if len(selcells) > 0: g.putcells(selcells, newx - x, newy - y)
g.fitsel()