File: make-torus.lua

package info (click to toggle)
golly 3.3-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 20,176 kB
  • sloc: cpp: 72,638; ansic: 25,919; python: 7,921; sh: 4,245; objc: 3,721; java: 2,781; xml: 1,362; makefile: 530; javascript: 279; perl: 69
file content (28 lines) | stat: -rwxr-xr-x 748 bytes parent folder | download | duplicates (3)
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
-- Use the current selection to create a toroidal universe.
-- Author: Andrew Trevorrow (andrew@trevorrow.com), Apr 2016.

local g = golly()

local selrect = g.getselrect()
if #selrect == 0 then g.exit("There is no selection.") end

local x, y, wd, ht = table.unpack(selrect)
local selcells = g.getcells(selrect)

if not g.empty() then
    g.clear(0)
    g.clear(1)
end

-- get current rule, remove any existing suffix, then add new suffix
local rule = g.getrule()
rule = rule:match("^(.+):") or rule
g.setrule(string.format("%s:T%d,%d", rule, wd, ht))

local newx = -math.floor(wd/2)
local newy = -math.floor(ht/2)
selrect[1] = newx
selrect[2] = newy
g.select(selrect)
if #selcells > 0 then g.putcells(selcells, newx - x, newy - y) end
g.fitsel()