File: invert.pl

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 (30 lines) | stat: -rw-r--r-- 778 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
26
27
28
29
30
# Invert all cell states in the current selection.
# Author: Andrew Trevorrow (andrew@trevorrow.com), May 2007.
# Updated to use g_numstates command, Jun 2008.

use strict;
use Time::HiRes qw (time);

my @rect = g_getselrect();
g_exit("There is no selection.") if @rect == 0;
my $x = $rect[0];
my $y = $rect[1];
my $wd = $rect[2];
my $ht = $rect[3];

my $oldsecs = time;
my $maxstate = g_numstates() - 1;

for (my $row = $y; $row < $y + $ht; $row++) {
   # if large selection then give some indication of progress
   my $newsecs = time;
   if ($newsecs - $oldsecs >= 1.0) {
      $oldsecs = $newsecs;
      g_update();
   }
   for (my $col = $x; $col < $x + $wd; $col++) {
      g_setcell($col, $row, $maxstate - g_getcell($col, $row));
   }
}

g_fitsel() if !g_visrect(@rect);