在 pygame 表面中将白色像素的随机子集设为黑色
我有一个 pygame 表面(一些由 font.render 创建的文本),除了一些像素是白色之外,大部分是透明的。我想将这些白色像素的一半改为黑色。我知道我可以迭代每个像素,通过 get_at() 检查它是否是白色并使用 set_at() 更改其颜色,但我突然想到必须有一种更快的方法来告诉 pygame 获取所有白色像素并更改随机一半为黑色。有什么想法吗?
I have a pygame surface (some text created by font.render) that is mostly transparent except some pixels are white. I'd like to change half of these white pixels black. I know I could iterate through each pixel, checking whether it is white by get_at() and changing its color using set_at(), but it strikes me that there must be a faster way of telling pygame to grab all the white pixels and change a random half of them to black. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要遍历所有像素来检查它们是否是白色的。获得白人列表后,请执行以下操作:
Python 文档 - 随机
I think you'll need to iterate through all the pixels to check if they're white. Once you have the list of whites, do something like:
Python Documentation - random