Skip to content

Commit 08ddf37

Browse files
committed
Add the nonogram-to-html script
1 parent 6a5b59e commit 08ddf37

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

examples/nonogram-to-html.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Converts the output from the nonogram Sentient program into a HTML document
2+
# that displays the result in a grid.
3+
#
4+
# $ sentient --run nonogram.json | ruby nonogram-to-html.rb > grid.html
5+
6+
require "json"
7+
8+
result = JSON.parse(STDIN.read)
9+
grid = result.fetch("grid")
10+
11+
grid.each do |row|
12+
print "<div class='nonogram-row'>"
13+
row.each do |cell|
14+
html_class = cell ? "shaded" : "blank"
15+
print "<div class='cell #{html_class}'></div>"
16+
end
17+
print "</div>"
18+
end
19+
20+
puts <<-CSS
21+
<style>
22+
.nonogram-row .cell {
23+
display: inline-block;
24+
width: 20px;
25+
height: 20px;
26+
border: 1px solid black;
27+
}
28+
29+
.nonogram-row .shaded {
30+
background: black;
31+
}
32+
</style>
33+
CSS

0 commit comments

Comments
 (0)