forked from pi3d/pi3d_demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Conway.py
39 lines (32 loc) · 1.19 KB
/
Conway.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/python
from __future__ import absolute_import, division, print_function, unicode_literals
""" GPU doing conways game of life. ESC to quit
this shows how it is possible to recycle images from the renderbuffer
and use the very fast processing speed of the GPU to do certain tasks.
"""
import ctypes
import demo
import pi3d
WIDTH = 800
HEIGHT = 800
DISPLAY = pi3d.Display.create(w=WIDTH, h=HEIGHT)
CAMERA = pi3d.Camera(is_3d=False)
shader = pi3d.Shader("conway")
tex = []
tex.append(pi3d.Texture("textures/Roof.png", mipmap=False))
tex.append(pi3d.Texture("textures/Roof.png", mipmap=False))
sprite = pi3d.Sprite(camera=CAMERA, w=WIDTH, h=HEIGHT, x=0.0, y=0.0, z=1.0)
sprite.set_draw_details(shader, [tex[0]])
sprite.set_2d_size(WIDTH, HEIGHT, 0.0, 0.0) # used to get pixel scale by shader
ti = 0 # variable to toggle between two textures
mykeys = pi3d.Keyboard()
while DISPLAY.loop_running():
sprite.draw()
ti = (ti+1) % 2
pi3d.opengles.glBindTexture(pi3d.GL_TEXTURE_2D, tex[ti]._tex)
pi3d.opengles.glCopyTexImage2D(pi3d.GL_TEXTURE_2D, 0, pi3d.GL_RGB, 0, 0, WIDTH, HEIGHT, 0)
sprite.set_draw_details(shader, [tex[ti]])
if mykeys.read() == 27:
mykeys.close()
DISPLAY.destroy()
break