File: invert.py

package info (click to toggle)
golly 2.3-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 10,080 kB
  • sloc: cpp: 41,951; python: 6,339; sh: 3,912; perl: 1,172; java: 49; makefile: 47
file content (25 lines) | stat: -rw-r--r-- 721 bytes parent folder | download
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
# Invert all cell states in the current selection.
# Author: Andrew Trevorrow (andrew@trevorrow.com), Jun 2006.
# Updated to use exit command, Nov 2006.
# Updated to use numstates command, Jun 2008.

from glife import rect
from time import time
import golly as g

r = rect( g.getselrect() )
if r.empty: g.exit("There is no selection.")

oldsecs = time()
maxstate = g.numstates() - 1

for row in xrange(r.top, r.top + r.height):
   # if large selection then give some indication of progress
   newsecs = time()
   if newsecs - oldsecs >= 1.0:
      oldsecs = newsecs
      g.update()
   for col in xrange(r.left, r.left + r.width):
      g.setcell(col, row, maxstate - g.getcell(col, row))

if not r.visible(): g.fitsel()