File: make-torus.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 (29 lines) | stat: -rw-r--r-- 732 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
# Use the current selection to create a toroidal universe.
# Author: Andrew Trevorrow (andrew@trevorrow.com), Oct 2010.

use strict;

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

my $selcells = g_getcells(@selrect);
if (!g_empty()) {
   g_clear(0);
   g_clear(1);
}

# get current rule, remove any existing suffix, then add new suffix
my ($rule, $suffix) = split(":",g_getrule(),2);
g_setrule("$rule:T$wd,$ht");

my $newx = -int($wd/2);
my $newy = -int($ht/2);
$selrect[0] = $newx;
$selrect[1] = $newy;
g_select(@selrect);
g_putcells($selcells, $newx - $x, $newy - $y) if length($selcells) > 0;
g_fitsel();