From b9dd43643591591daba08f186e9330dd76f2e8de Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Thu, 27 Oct 2016 20:21:32 +0200 Subject: [PATCH] Lissajous Curve --- lissajous.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lissajous.py diff --git a/lissajous.py b/lissajous.py new file mode 100644 index 0000000..044246f --- /dev/null +++ b/lissajous.py @@ -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() +