Animated background with waves
Require PyMT 0.4
import math
from pymt import *
from OpenGL.GL import *
class Background(MTWidget):
def __init__(self):
super(Background, self).__init__()
self.background = Image('background.jpg')
def draw(self):
w = getWindow()
w.gradient = False
set_color(1, 1, 1)
drawTexturedRectangle(self.background.texture, size=w.size)
h2 = w.height / 2.
l = []
l2 = []
t = getClock().get_time()
for x in xrange(0, w.width + 50, 50):
l.append(x)
l.append(h2 - 120 + math.sin(x * 0.01 + t * 0.3) * 30)
l.append(x)
l.append(h2 + 120 + math.sin(0.01 + x * 0.01 + t * 0.15) * 30)
l2.append(x)
l2.append(h2 - 200 + math.cos(x * 0.01 - t * 0.2) * 30)
l2.append(x)
l2.append(h2 + 140 + math.cos(0.01 + x * 0.01 - t * 0.3) * 30)
set_color(65 / 255., 123 / 255., 161 / 255., .2)
drawPolygon(l, style=GL_TRIANGLE_STRIP)
drawPolygon(l2, style=GL_TRIANGLE_STRIP)
if __name__ == '__main__':
runTouchApp(Background())
from pymt import *
from OpenGL.GL import *
class Background(MTWidget):
def __init__(self):
super(Background, self).__init__()
self.background = Image('background.jpg')
def draw(self):
w = getWindow()
w.gradient = False
set_color(1, 1, 1)
drawTexturedRectangle(self.background.texture, size=w.size)
h2 = w.height / 2.
l = []
l2 = []
t = getClock().get_time()
for x in xrange(0, w.width + 50, 50):
l.append(x)
l.append(h2 - 120 + math.sin(x * 0.01 + t * 0.3) * 30)
l.append(x)
l.append(h2 + 120 + math.sin(0.01 + x * 0.01 + t * 0.15) * 30)
l2.append(x)
l2.append(h2 - 200 + math.cos(x * 0.01 - t * 0.2) * 30)
l2.append(x)
l2.append(h2 + 140 + math.cos(0.01 + x * 0.01 - t * 0.3) * 30)
set_color(65 / 255., 123 / 255., 161 / 255., .2)
drawPolygon(l, style=GL_TRIANGLE_STRIP)
drawPolygon(l2, style=GL_TRIANGLE_STRIP)
if __name__ == '__main__':
runTouchApp(Background())
And the Background used in the example:

