私はある種の「ランダムジェネレーター」を実行しようとしました。隣接するポイントがいくつかあり、それらの明るさに応じて、多かれ少なかれ選択される可能性があります。
ポイントは、座標と値を持つオブジェクトでx
あり、その明るさを保存します。y
b
私のアプローチは、aと値(両方とも0と1の間の何か)を持つp
オブジェクトを(p
可能性のために)設定することでした-との値の違いはそれらの明るさに依存します。start
end
start
end
次に、乱数を生成し、すべてのポイントをループして、乱数がプロパティの間にあるかどうかを確認しstart
ますend
。1ポイントstart
の値は前のポイントのend
値であるため、1つのポイントのみを選択する必要がありますが、代わりにランダムな量のポイントが選択されます。
したがって、ランダムな値とポイントstart
およびend
プロパティをログに記録しました。次のコードを除いて、すべてが機能したように見えます
for (i = 0; i < numAdjacentPoints; i++) {
// set some shorthands
curr_point = adjacentPoints[i];
// if there is no previous point, we start with 0
prev_point = ((i === 0) ? {p: {end: 0}} : adjacentPoints[i-1]);
// initiate a probability object
curr_point.p = {};
// set a start value (the start value is the previous point's end value)
curr_point.p.start = prev_point.p.end;
// set an end value (the start value + the point's brightness' share of totalBrightness)
// -> points with higher darkness (255-b) are more have a higher share -> higher probability to get grown on
curr_point.p.end = curr_point.p.start + (255 - curr_point.b) / totalBrightness;
// if the random value is between the current point's p values, it gets grown on
if (curr_point.p.start < rand < curr_point.p.end) {
// add the new point to the path array
path[path.length] = curr_point;
// set the point's brightness to white -> it won't come into range any more
curr_point.b = 255;
console.log(" we've got a winner! new point is at "+curr_point.x+":"+curr_point.y);
console.log(" "+curr_point.p.start.toFixed(2)+" < "+rand.toFixed(2)+" < "+curr_point.p.end.toFixed(2));
}
};
これを出力します:
we've got a winner! new point is at 300:132 mycelium.php:269
0.56 < 0.53 < 0.67 mycelium.php:270
we've got a winner! new point is at 301:130 mycelium.php:269
0.67 < 0.53 < 0.78 mycelium.php:270
we've got a winner! new point is at 301:131 mycelium.php:269
0.78 < 0.53 < 0.89 mycelium.php:270
we've got a winner! new point is at 301:132 mycelium.php:269
0.89 < 0.53 < 1.00
-> WTF?0.56 < 0.53 < 0.67
??