one-file-projects/lissajous.py

42 lines
1.1 KiB
Python
Raw Normal View History

2016-10-27 20:21:32 +02:00
#!/usr/bin/env python
from game import *
from math import sin, pi
class Lissajous(Game):
def __init__(self, fx, fy):
self.fx = fx
self.fy = fy
self.width = 1000
self.height = 600
self.time = 0
self.old_point = self.get_pos()
self.new_point = self.old_point
self.reset = False
super(Lissajous, self).__init__(self.width, self.height, 100)
def get_pos(self):
return ( int( (1+sin(2*pi*self.fx*self.time)) / 2 * self.width), int( (1+sin(2*pi*self.fy*self.time)) / 2 * self.height) )
def on_update(self, dtime):
self.old_point = self.new_point
self.time += dtime
self.new_point = self.get_pos()
def on_render(self, srfc):
WHITE = (255,255,255)
BLACK = (0,0,0)
if self.reset:
srfc.fill(BLACK)
self.reset = False
pygame.draw.line( srfc, WHITE, self.old_point, self.new_point )
def on_event(self, event):
if event.type == MOUSEBUTTONDOWN and event.button == 1:
self.reset = True
if __name__ == "__main__":
Lissajous(0.5,0.325).on_execute()