File: density.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 (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));
}