I'm generating a grid of objects, each of which has one of 3 colors.(我正在生成一个对象网格,每个对象都有3种颜色之一。)
Assume I'm filling a particular grid cell.(假设我正在填充特定的网格单元。) I know that around this cell there are, for example, 1 object of color 0
, 1 of color 1
and 2 of color 2
, so:(我知道这个细胞周围有,例如,颜色的1个物体0
,颜色的1 1
和色2 2
,所以:)
const surroundings = { 0: 1, 1: 1, 2: 2 }
Now I want to assign a color to the current cell I'm working with.(现在,我想为正在使用的当前单元格分配颜色。) I need to count probabilities for each color to be used.(我需要计算要使用的每种颜色的概率。) To make it look pleasing, I want it more likely to be different from its surroundings.(为了使它看起来令人愉悦,我希望它与周围环境有所不同。) So in the case above the probabilities could be { 0: 0.4, 1: 0.4, 2: 0.2 }
.(因此,在上述情况下,概率可能是{ 0: 0.4, 1: 0.4, 2: 0.2 }
。)
I'm sure there is an implementation of such operation in the probability theory, but I'm having trouble finding the correct term for it.(我敢肯定,概率论中有这样一种运算的实现,但是我很难找到它的正确术语。) In the example I gave the probabilities could be different, because I have no idea how to calculate them.(在示例中,我给出的概率可能不同,因为我不知道如何计算它们。) But for colors 0
and 1
they should certainly be equal and for color 2
it should be the smallest.(但是对于颜色0
和1
它们肯定应该相等,而对于颜色2
它应该是最小的。)
ask by Alex Chashin translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…