File: density.pl

package info (click to toggle)
golly 2.1-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 9,560 kB
  • ctags: 5,064
  • sloc: cpp: 38,119; python: 3,203; perl: 1,121; makefile: 58; java: 49; sh: 22
file content (14 lines) | stat: -rw-r--r-- 369 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Calculates the density of live cells in the current pattern.
# Author: Andrew Trevorrow (andrew@trevorrow.com), June 2007.

use strict;

my @rect = g_getrect();
g_exit("The pattern is empty.") if @rect == 0;

my $d = g_getpop() / ($rect[2] * $rect[3]);
if ($d < 0.000001) {
   g_show(sprintf("Density = %.1e",$d));
} else {
   g_show(sprintf("Density = %.6f",$d));
}