Skip to content

Commit ba24e1a

Browse files
committed
Draw caps on crosses to hide rough edges
1 parent 93647a9 commit ba24e1a

1 file changed

Lines changed: 45 additions & 4 deletions

File tree

src/variety/bunnyhop.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
paint: function() {
223223
this.drawBGCells();
224224
this.drawGrid();
225+
this.drawCaps();
225226
this.drawLines();
226227
this.drawPekes();
227228
},
@@ -235,6 +236,46 @@
235236
return null;
236237
},
237238

239+
getCrossColor: function(cross) {
240+
var color = null;
241+
for (var dir in cross.adjborder) {
242+
var border = cross.adjborder[dir];
243+
var newColor = this.getLineColor(border);
244+
245+
if (border.error === 1) {
246+
return newColor;
247+
} else if (!color) {
248+
color = newColor;
249+
}
250+
}
251+
return color;
252+
},
253+
254+
drawCaps: function() {
255+
var g = this.vinc("caps");
256+
g.strokeStyle = null;
257+
258+
var basewidth = Math.max(this.bw / 4, 2);
259+
var xlist = this.range.crosses;
260+
for (var i = 0; i < xlist.length; i++) {
261+
var cross = xlist[i];
262+
g.vid = "b_cap" + cross.id;
263+
264+
var color = this.getCrossColor(cross);
265+
266+
if (!!color) {
267+
var px = cross.bx * this.bw,
268+
py = cross.by * this.bh;
269+
270+
var radius = basewidth / 2;
271+
g.fillStyle = color;
272+
g.shapeCircle(px, py, radius);
273+
} else {
274+
g.vhide();
275+
}
276+
}
277+
},
278+
238279
drawLines: function() {
239280
var g = this.vinc("line");
240281

@@ -260,18 +301,18 @@
260301
g.beginPath();
261302
g.moveTo(px, py - this.bh);
262303
if (border.line === 1) {
263-
g.lineTo(px - this.bw / 2, py);
304+
g.lineTo(px - this.bw / 1.5, py);
264305
} else {
265-
g.lineTo(px + this.bw / 2, py);
306+
g.lineTo(px + this.bw / 1.5, py);
266307
}
267308
g.lineTo(px, py + this.bh);
268309
} else {
269310
g.beginPath();
270311
g.moveTo(px - this.bw, py);
271312
if (border.line === 1) {
272-
g.lineTo(px, py - this.bh / 2);
313+
g.lineTo(px, py - this.bh / 1.5);
273314
} else {
274-
g.lineTo(px, py + this.bh / 2);
315+
g.lineTo(px, py + this.bh / 1.5);
275316
}
276317
g.lineTo(px + this.bw, py);
277318
}

0 commit comments

Comments
 (0)