pyglet中的按像素绘制(python) [英] pixelwise drawing in pyglet (python)

查看:225
本文介绍了pyglet中的按像素绘制(python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好。我厌倦了谷歌搜索和阅读大量没有结果的文档。

OK. I'm tired of googling and reading throught lots of documentation with no results.

我的目标很简单:让pyglet逐像素绘制图像。

My aim is simple: get pyglet to draw an image pixel by pixel.

我一直在搜索没有结果的小时。谁能给出一个简短程序的示例,该程序绘制一个逐像素指定颜色的显示吗?例如:绘制从黑色到白色的渐变。

I've been searching for hours with no results. Can anyone give an example of a short program that draws in a display specifying the color pixel by pixel? For example: drawing a gradient from black to white.

推荐答案

只要您意识到这将需要长时间 ...:

As long as you realize this is going to take a long time...:

pyglet.graphics.draw 可以在以下情况下获得一个或多个点您可以通过 pyglet.gl.GL_POINTS 进行传递,还可以传递颜色和坐标等属性。例如:

pyglet.graphics.draw can drawn one or more points when you pass it pyglet.gl.GL_POINTS, and you can pass attributes such as color as well as coordinates. For example:

for i in range(50):
    for j in range(50):
        color = int(2.56 * (i + j))
        pyglet.graphics.draw(1, pyglet.gl.GL_POINTS,
            ('v2i', (i, j)),
            ('c3B', (color, color, color))
        )

绘制a 50 x 50平方,从黑色到白色呈对角线渐变。只是不要期望这样做会特别快;-)-GL实际上是面向具有更高抽象水平的图形,而不是逐像素绘制。

draws a 50 by 50 square with a diagonal gradient from black to white-ish. Just don't expect it to be particularly fast at doing that;-) -- GL is really oriented to graphics with much higher level of abstraction, not "pixel by pixel" painting.

您可以通过一次计算(例如)一行并绘制而不是单独绘制像素来获得一点额外的速度。但是它仍然不会很快!-)

You could get a modicum of extra speed by computing (say) a row at a time, and drawing that, instead of actually drawing pixels singly. But it still won't be super-fast!-)

这篇关于pyglet中的按像素绘制(python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆