Python 需要发布你的密码,我解决了。这是我这方面的一个简单错误。谢谢你,詹姆斯。有限的随机范围解决方案非常有效。感谢你提出了关于偏向255的极好观点,我没有考虑到这一点。我尝试过限制随机范围,但得到了一条“'int'对象不可调用”消息。我喜欢在刻度两端都有一个随机
Python 需要发布你的密码,我解决了。这是我这方面的一个简单错误。谢谢你,詹姆斯。有限的随机范围解决方案非常有效。感谢你提出了关于偏向255的极好观点,我没有考虑到这一点。我尝试过限制随机范围,但得到了一条“'int'对象不可调用”消息。我喜欢在刻度两端都有一个随机,python,random,rgb,noise,Python,Random,Rgb,Noise,需要发布你的密码,我解决了。这是我这方面的一个简单错误。谢谢你,詹姆斯。有限的随机范围解决方案非常有效。感谢你提出了关于偏向255的极好观点,我没有考虑到这一点。我尝试过限制随机范围,但得到了一条“'int'对象不可调用”消息。我喜欢在刻度两端都有一个随机的“区域”,而不是硬帽。@BFG.Digital我不知道为什么会出现“int object is not callable”(int object is not callable)错误。听起来像是我们中的一个人用一组额外的括号或缺少的逗号打错了
需要发布你的密码,我解决了。这是我这方面的一个简单错误。谢谢你,詹姆斯。有限的随机范围解决方案非常有效。感谢你提出了关于偏向255的极好观点,我没有考虑到这一点。我尝试过限制随机范围,但得到了一条“'int'对象不可调用”消息。我喜欢在刻度两端都有一个随机的“区域”,而不是硬帽。@BFG.Digital我不知道为什么会出现“int object is not callable”(int object is not callable)错误。听起来像是我们中的一个人用一组额外的括号或缺少的逗号打错了字。如果你想解决这个问题,你需要发布你的代码。我解决了。这是我这方面的一个简单错误。谢谢你,詹姆斯。有限的随机范围解决方案非常有效。
red,green,blue = (253, 4, 130)
print(
(np.random.randint(red-10,red+10),
np.random.randint(green-10,green+10),
np.random.randint(blue-10,blue+10)))
# output values cannot be over 255 or under 0
#The following output would not be ok.
>>>(257, -2, 132)
import numpy as np
red,green,blue = (253, 4, 130)
def rand_within_rgb(inp, thres):
if np.random.randint(inp - thres, inp + thres) > 255:
return 255
elif np.random.randint(inp - thres, inp + thres) < 0:
return 0
else:
return np.random.randint(inp - thres, inp + thres)
print((rand_within_rgb(red, 10),
rand_within_rgb(green, 10),
rand_within_rgb(blue, 10)))
(253, 0, 127)
def rand_within_rgb(inp, thres):
if inp + thres > 255:
return np.random.randint(inp - thres, 255)
elif inp - thres < 0:
return np.random.randint(0, inp + thres)
else:
return np.random.randint(inp - thres, inp + thres)