1 | gridColor = 'black'
|
2 | pathColor = '#d3ac0d'
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | horizontal = """
|
8 | <symbol viewBox="10 -10 80 20" z-index="ZZZ">
|
9 | <line x1="5" x2="95" y1="0" y2="0" stroke-width="20" stroke="COLOR"/>
|
10 | </symbol>
|
11 | """
|
12 |
|
13 | vertical = """
|
14 | <symbol viewBox="-10 10 20 80" z-index="ZZZ">
|
15 | <line y1="5" y2="95" x1="0" x2="0" stroke-width="20" stroke="COLOR"/>
|
16 | </symbol>
|
17 | """
|
18 |
|
19 | dot = (solution) -> ->
|
20 | s = '<symbol viewBox="-10 -10 20 20" z-index="ZZZ">'
|
21 |
|
22 |
|
23 | if (@neighbor(-1,0).includes('-') and @neighbor(+1,0).includes('-')) or
|
24 | (@neighbor(0,-1).includes('|') and @neighbor(0,+1).includes('|'))
|
25 | s += """<rect x="-10" y="-10" width="20" height="20" fill="#{gridColor}"/>"""
|
26 | else
|
27 | s += """<circle x="0" y="0" r="10" fill="#{gridColor}"/>"""
|
28 | if @neighbor(-1,0).includes '-'
|
29 | s += """<rect x="-10" y="-10" width="10" height="20" fill="#{gridColor}"/>"""
|
30 | if @neighbor(+1,0).includes '-'
|
31 | s += """<rect x="0" y="-10" width="10" height="20" fill="#{gridColor}"/>"""
|
32 | if @neighbor(0,-1).includes '|'
|
33 | s += """<rect x="-10" y="-10" width="20" height="10" fill="#{gridColor}"/>"""
|
34 | if @neighbor(0,+1).includes '|'
|
35 | s += """<rect x="-10" y="0" width="20" height="10" fill="#{gridColor}"/>"""
|
36 | if @neighbor(-1,0).includes('-s') or @neighbor(+1,0).includes('-s') or
|
37 | @neighbor(0,-1).includes('|s') or @neighbor(0,+1).includes('|s') or
|
38 | solution
|
39 | s = s.replace /ZZZ/, 3
|
40 | if (@neighbor(-1,0).includes('-s') and @neighbor(+1,0).includes('-s')) or
|
41 | (@neighbor(0,-1).includes('|s') and @neighbor(0,+1).includes('|s'))
|
42 | s += """<rect x="-10" y="-10" width="20" height="20" fill="#{pathColor}"/>"""
|
43 | else
|
44 | s += """<circle x="0" y="0" r="10" fill="#{pathColor}"/>"""
|
45 | if @neighbor(-1,0).includes '-s'
|
46 | s += """<rect x="-10" y="-10" width="10" height="20" fill="#{pathColor}"/>"""
|
47 | if @neighbor(+1,0).includes '-s'
|
48 | s += """<rect x="0" y="-10" width="10" height="20" fill="#{pathColor}"/>"""
|
49 | if @neighbor(0,-1).includes '|s'
|
50 | s += """<rect x="-10" y="-10" width="20" height="10" fill="#{pathColor}"/>"""
|
51 | if @neighbor(0,+1).includes '|s'
|
52 | s += """<rect x="-10" y="0" width="20" height="10" fill="#{pathColor}"/>"""
|
53 | else
|
54 | s = s.replace /ZZZ/, 0
|
55 | s + '</symbol>'
|
56 |
|
57 | blank = ->
|
58 | if @i % 2 == 1
|
59 | h = 80
|
60 | else
|
61 | h = 20
|
62 | if @j % 2 == 1
|
63 | w = 80
|
64 | else
|
65 | w = 20
|
66 | """
|
67 | <symbol viewBox="0 0 #{w} #{h}"/>
|
68 | """
|
69 |
|
70 | start = (solution) -> ->
|
71 | s = """
|
72 | <symbol viewBox="-10 -10 20 20" overflowBox="-25 -25 50 50" z-index="2">
|
73 | <circle cx="0" cy="0" r="25" fill="COLOR" />
|
74 | """
|
75 | if @neighbor(-1,0).includes('-s') + @neighbor(+1,0).includes('-s') +
|
76 | @neighbor(0,-1).includes('|s') + @neighbor(0,+1).includes('|s') == 1 or
|
77 | solution
|
78 | s = s.replace /COLOR/g, pathColor
|
79 | else
|
80 | s = s.replace /COLOR/g, gridColor
|
81 | if @neighbor(-1,0).includes('-s') or @neighbor(+1,0).includes('-s') or
|
82 | @neighbor(0,-1).includes('|s') or @neighbor(0,+1).includes('|s')
|
83 |
|
84 | if (@neighbor(-1,0).includes('-s') and @neighbor(+1,0).includes('-s')) or
|
85 | (@neighbor(0,-1).includes('|s') and @neighbor(0,+1).includes('|s'))
|
86 | s += """<rect x="-10" y="-10" width="20" height="20" fill="#{pathColor}"/>"""
|
87 | else
|
88 | s += """<circle x="0" y="0" r="10" fill="#{pathColor}"/>"""
|
89 | if @neighbor(-1,0).includes '-s'
|
90 | s += """<rect x="-10" y="-10" width="10" height="20" fill="#{pathColor}"/>"""
|
91 | if @neighbor(+1,0).includes '-s'
|
92 | s += """<rect x="0" y="-10" width="10" height="20" fill="#{pathColor}"/>"""
|
93 | if @neighbor(0,-1).includes '|s'
|
94 | s += """<rect x="-10" y="-10" width="20" height="10" fill="#{pathColor}"/>"""
|
95 | if @neighbor(0,+1).includes '|s'
|
96 | s += """<rect x="-10" y="0" width="20" height="10" fill="#{pathColor}"/>"""
|
97 | s + '</symbol>'
|
98 |
|
99 | square = """
|
100 | <symbol viewBox="0 0 80 80">
|
101 | <rect x="20" y="20" width="40" height="40" rx="15" ry="15" fill="COLOR" stroke="COLOR"/>
|
102 | </symbol>
|
103 | """
|
104 |
|
105 | star = """
|
106 | <symbol viewBox="0 0 80 80">
|
107 | <rect x="25" y="25" width="30px" height="30px" fill="COLOR" stroke="COLOR" />
|
108 | <rect x="25" y="25" width="30px" height="30px" transform="rotate(45 40 40)" fill="COLOR" stroke="COLOR" />
|
109 | </symbol>
|
110 | """
|
111 |
|
112 | triangle = (k) ->
|
113 | r = 8
|
114 | addl = r*2 + 4
|
115 | h = r*1.73205/2
|
116 | xTransform = (k-1)*addl
|
117 | svg = """<symbol viewBox="-40 -40 80 80">"""
|
118 | for i in [0...k]
|
119 | svg += """
|
120 | <polygon fill="orange" stroke="none"
|
121 | points="0,#{-h} #{r},#{h} #{-r},#{h}"
|
122 | transform="translate(#{i*addl-xTransform/2},0)" />
|
123 | """
|
124 | svg + "</symbol>"
|
125 |
|
126 | map =
|
127 | '-': horizontal.replace(/COLOR/g, gridColor).replace(/ZZZ/, 1)
|
128 | '-s': horizontal.replace(/COLOR/g, pathColor).replace(/ZZZ/, 4)
|
129 | '|': vertical.replace(/COLOR/g, gridColor).replace(/ZZZ/, 1)
|
130 | '|s': vertical.replace(/COLOR/g, pathColor).replace(/ZZZ/, 4)
|
131 | '': blank
|
132 | ' ': blank
|
133 | '.': dot false
|
134 | '.s': dot true
|
135 | start: start false
|
136 | starts: start true
|
137 | '1': triangle 1
|
138 | '2': triangle 2
|
139 | '3': triangle 3
|
140 |
|
141 | colorMap =
|
142 | r: 'red'
|
143 | g: 'green'
|
144 | b: 'blue'
|
145 | c: 'cyan'
|
146 | o: 'orange'
|
147 | w: '#dddddd' ## avoiding 'white' given currently white background
|
148 | k: 'black'
|
149 | y: 'yellow'
|
150 | m: 'magenta'
|
151 |
|
152 | (key) ->
|
153 | return map[key] if key of map
|
154 | switch key[key.length-1]
|
155 | when 'q'
|
156 | square.replace /COLOR/g, colorMap[key[0]]
|
157 | when '*'
|
158 | star.replace /COLOR/g, colorMap[key[0]]
|
159 | else
|
160 | null
|
161 |
|
\ | No newline at end of file |