#!/usr/bin/perl
# Sierpinski renderer, XOR based
# If you start the cellular automaton of rule 90 with a single cell,
# subsequent rows will form a Sierpinski Triangle
# This script can be used to generate rule 90 patterns as well.
# by polprog; http://polprog.net 2018
# BSD 3-clause licence


# Terminal size 
my $termwidth = `tput cols`;
my $termheight = `tput lines` -1;

my @line1 = (0) x $termwidth;
my @line2 = (0) x $termwidth;

$line1[int $termwidth/2] = 1; #initialize the Rule 90 generator

for (my $i = 0; $i < $termheight; $i++){
    for(my $j = 1; $j < $termwidth - 1; $j++){
        if($line2[$j] != 0) { print "\033[7m#\033[0m";}
        else { print " ";}
        $line2[$j] = $line1[$j-1] ^ $line1[$j+1]; #Rule 90 is a simple XOR
    }
    @line1 = @line2; # replace previous line with the next
    print "\n";
}
