The code is from here. The author mentions that the two random values balance
and max-offset
are, 'one for whether midpoints are more likely to be offset inward or outward, and another for how far midpoints can be offset'.
I tried averaging parent vertices balance
and max-offset
, tried different methods for balance
(float, int, bool), and different ways of balance
influencing max-offset
, but the results are either too homogeneous or coils too much, and have no relationship with the demo (maps generated prior to this step are matching though).
I simply want to know how the variables balance
and max-offset
are factored in to calculate the midpoint displacement.
(defn offset-midpoint-rough
[{[x1 y1] :position b1 :balance mo1 :max-offset}
{[x2 y2] :position b2 :balance mo2 :max-offset}]
(let [mx (/ (+ x1 x2) 2)
my (/ (+ y1 y2) 2)
vx (- (- y1 y2))
vy (- x1 x2)
balance (/ (+ b1 b2) 2)
max-offset (/ (+ mo1 mo2) 2)
d (* max-offset (- (rand) balance))]
{:position [(+ mx (* d vx))
(+ my (* d vy))]
:balance balance
:max-offset max-offset}))
BTW, I have the rest figured out without referring to the code posted, based on the textual description, and I'm coding in c# (Unity3D).
EDIT: Image showing comparison with previous code (blue highlight is new code which confounds me).