-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgame-of-life-cluster
70 lines (54 loc) · 1.36 KB
/
game-of-life-cluster
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env perl
use strict;
use warnings;
use MIDI::Util qw(setup_score); # https://metacpan.org/release/MIDI-Util
use Game::Life;
my $bpm = shift || 100;
my $score = setup_score( bpm => $bpm );
my @source = qw/ C D E F G A B /;
# Create a LoL of source notes with incrementing octaves
my $octave = scalar @source;
my $matrix;
while ( $octave ) {
push @$matrix, [ map { $_ . $octave } @source ];
$octave--;
}
my $blinker = [
[0,0,0],
[1,1,1],
[0,0,0]
];
my $glider = [
[1,1,1],
[1,0,0],
[0,1,0]
];
my $g = Game::Life->new( scalar @source );
# Place the blinker on the grid
#$g->place_points( 2, 2, $blinker );
# Place the glider at the bottom-right of the grid
$g->place_points( 4, 4, $glider );
# Incrementally glide to the top-left of the grid
for my $n ( 1 .. 17 ) {
print "Iteration $n:\n";
my $grid = $g->get_grid;
# Find the note cluster to add to the score
my @notes;
my $i = 0;
for my $row ( @$grid ) {
my $j = 0;
for my $cell ( @$row ) {
push @notes, $matrix->[$i][$j] if $cell;
$j++;
}
$i++;
print map { $_ ? 'x ' : '. ' } @$row;
print "\n";
}
print "@notes\n\n";
# Add the note cluster and a rest to the score
$score->n( 'qn', @notes );
$score->r('qn');
$g->process;
}
$score->write_score( $0 . '.mid' );