Lissajous Curve
This commit is contained in:
parent
d81b6383c0
commit
b9dd436435
1 changed files with 41 additions and 0 deletions
41
lissajous.py
Normal file
41
lissajous.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
#!/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()
|
||||||
|
|
Loading…
Reference in a new issue