File: density.lua

package info (click to toggle)
golly 3.3-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 20,176 kB
  • sloc: cpp: 72,638; ansic: 25,919; python: 7,921; sh: 4,245; objc: 3,721; java: 2,781; xml: 1,362; makefile: 530; javascript: 279; perl: 69
file content (14 lines) | stat: -rwxr-xr-x 396 bytes parent folder | download | duplicates (4)
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), March 2016.

local g = golly()

local bbox = g.getrect()
if #bbox == 0 then g.exit("The pattern is empty.") end

local d = g.getpop() / (bbox[3] * bbox[4])
if d < 0.000001 then
    g.show(string.format("Density = %.1e", d))
else
    g.show(string.format("Density = %.6f", d))
end