generated from edemaine/reveal-pug-talk
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfigures.coffee
38 lines (36 loc) · 1.3 KB
/
figures.coffee
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
contents = (elt) ->
elt.innerText.trim()
.replace /^[ \t]+|[ \t]+$/gm, '' # remove indentation on each line
.replace /^\n+|\n+$/g, '' # remove initial/final line breaks
window.addEventListener 'DOMContentLoaded', ->
document.querySelectorAll('.puzzle').forEach (elt) ->
text = contents elt
puzzle = Puzzle.fromAscii text.replace /[%0]/g, '.'
elt.innerHTML = ''
svg = SVG().addTo elt
player = new Player svg, puzzle
if /[%0]/.test text
player.user = Puzzle.fromAscii (
text.replace /%/g, 'X'
.replace /0/g, 'O'
)
player.drawUser()
player.user.bad2x2s = (-> []) if elt.classList.contains 'no2x2'
player.drawErrors()
vertex = (color) -> ->
"""
<symbol viewBox="-0.5 -0.5 1 1">
#{if @neighbor(1, 0).key? then '<line x2="1" stroke="white" stroke-width="0.15"/>' else ''}
#{if @neighbor(0, 1).key? then '<line y2="1" stroke="white" stroke-width="0.15"/>' else ''}
<circle r="0.3" fill="#{color}" stroke="white" style="stroke-width: 0.1 !important"/>
</symbol>
"""
mapping = new svgtiler.Mapping
X: vertex '#0377fc'
x: vertex '#0377fc'
O: vertex '#c70000'
o: vertex '#c70000'
'.': vertex '#aaa'
svgtiler.renderDOM mapping, '.graph',
filename: 'graph.asc'
keepParent: true