-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprinter.erl
More file actions
28 lines (22 loc) · 763 Bytes
/
printer.erl
File metadata and controls
28 lines (22 loc) · 763 Bytes
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
-module(printer).
-compile(export_all).
% A very simple display system for the Game of Life cell store - just
% prints either "." for an empty cell or "X" for a full one.
% Print the default 100x100 grid, with 0,0 at the top left.
print() ->
print({0,0}, {99, 99}).
% Print an arbitrary grid with StartX,StartY at the top left and FinX,FinY
% at the bottom right.
print({StartX, StartY}, {FinX, FinY}) ->
[print_row(StartX, FinX, Y) || Y <- lists:seq(StartY, FinY)],
io:fwrite("~n", []),
ok.
%% Helper functions (not for external use):
print_row(StartX, FinX, Y) ->
[io:fwrite("~s", [print_cell({X, Y})]) || X <- lists:seq(StartX, FinX)],
io:fwrite("~n", []).
print_cell(Cell) ->
case cell_store:get_cell(Cell) of
true -> "X";
false -> "."
end.