rework client drawing code

This commit is contained in:
Nils Schneider 2015-06-27 01:37:36 +02:00
parent d170204b31
commit 4d69677ede
2 changed files with 25 additions and 34 deletions

View File

@ -288,27 +288,24 @@ define(["d3"], function (d3) {
if (clients === 0) if (clients === 0)
return return
var distance = 16 var startDistance = 16
var radius = 3 var radius = 3
var a = 1.2 var a = 1.2
var startAngle = Math.PI var startAngle = Math.PI
var angle = startAngle
for (var i = 0; i < clients; i++) { for (var orbit = 0, i = 0; i < clients; orbit++) {
if ((angle - startAngle) > 2 * Math.PI) { var distance = startDistance + orbit * 2 * radius * a
angle = startAngle var n = Math.floor((Math.PI * distance) / (a * radius))
distance += 2 * radius * a var delta = clients - i
}
var x = d.x + distance * Math.cos(angle) for (var j = 0; j < Math.min(delta, n); i++, j++) {
var y = d.y + distance * Math.sin(angle) var angle = 2 * Math.PI / n * j
var x = d.x + distance * Math.cos(angle + startAngle)
var y = d.y + distance * Math.sin(angle + startAngle)
ctx.moveTo(x, y) ctx.moveTo(x, y)
ctx.arc(x, y, radius, 0, 2 * Math.PI) ctx.arc(x, y, radius, 0, 2 * Math.PI)
}
var n = Math.floor((Math.PI * distance) / (a * radius))
var angleDelta = 2 * Math.PI / n
angle += angleDelta
} }
}) })

View File

@ -53,25 +53,19 @@ define(["leaflet", "jshashes"],
p.x -= s.x p.x -= s.x
p.y -= s.y p.y -= s.y
var distance = startDistance for (var orbit = 0, i = 0; i < clients; orbit++) {
var startAngle = d.startAngle var distance = startDistance + orbit * 2 * radius * a
var angle = startAngle var n = Math.floor((Math.PI * distance) / (a * radius))
var delta = clients - i
for (var i = 0; i < clients; i++) { for (var j = 0; j < Math.min(delta, n); i++, j++) {
if ((angle - startAngle) > 2 * Math.PI) { var angle = 2 * Math.PI / n * j
angle = startAngle var x = p.x + distance * Math.cos(angle + d.startAngle)
distance += 2 * radius * a var y = p.y + distance * Math.sin(angle + d.startAngle)
}
var x = p.x + distance * Math.cos(angle)
var y = p.y + distance * Math.sin(angle)
ctx.moveTo(x, y) ctx.moveTo(x, y)
ctx.arc(x, y, radius, 0, 2 * Math.PI) ctx.arc(x, y, radius, 0, 2 * Math.PI)
}
var n = Math.floor((Math.PI * distance) / (a * radius))
var angleDelta = 2 * Math.PI / n
angle += angleDelta
} }
}) })