File: invert.lua

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 (33 lines) | stat: -rwxr-xr-x 841 bytes parent folder | download | duplicates (4)
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
30
31
32
33
-- Invert all cell states in the current selection.
-- Author: Andrew Trevorrow (andrew@trevorrow.com), Mar 2016.

local g = golly()
local gp = require "gplus"

-- re-assigning inner loop functions results in a 10% speed up
local setcell = g.setcell
local getcell = g.getcell

local r = gp.rect(g.getselrect())
if r.empty then g.exit("There is no selection.") end

-- local t1 = os.clock()

local oldsecs = os.clock()
local maxstate = g.numstates() - 1

for row = r.top, r.bottom do
    -- if large selection then give some indication of progress
    local newsecs = os.clock()
    if newsecs - oldsecs >= 1.0 then
        oldsecs = newsecs
        g.update()
    end
    for col = r.left, r.right do
        setcell(col, row, maxstate - getcell(col, row))
    end
end

if not r.visible() then g.fitsel() end

-- g.show(""..(os.clock()-t1))