We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6a5b59e commit 08ddf37Copy full SHA for 08ddf37
examples/nonogram-to-html.rb
@@ -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