-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
87 lines (64 loc) · 2.09 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Modules used
import pygame
import time
class henon:
def __init__(self, y0, a, b):
self.y0 = y0
self.a = a
self.b = b
# Henon System
def henon_system(self, x, y):
return [1 - self.a*x**2 + y, self.b*x]
def main():
# Initializes display
pygame.init()
SIZE = (900, 600)
SCREEN = pygame.display.set_mode(SIZE)
pygame.display.set_caption("Henon Attractor") # Title
COLOR = (255, 255, 255) # Colour is white
pygame.display.flip()
clock = pygame.time.Clock()
# Initial display states.
running = True
pressed_return = False
# timer starts at 0.
timer = time.time()
# Initialised henon Attractor.
y0 = [0, 0]
a = 1.4 # Value for `a`
b = 0.3 # Value for `b`
hs = henon(y0, a, b)
while running:
clock.tick(60)
# Events
for event in pygame.event.get():
# Press the x in the top left corner to quit.
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
# press `q` to quit.
if event.key == pygame.K_q:
running = False
# Press `return` to start.
if event.key == pygame.K_RETURN:
pressed_return = True
# Sets the initial condition `y0`.
if not pressed_return:
[x, y] = hs.y0
# Check if the return key was pressed.
if pressed_return:
# henon system
[x_new, y_new] = hs.henon_system(x, y)
# Display coordinates
x_display = int(SIZE[0]/2 + x_new*300)
y_display = int(SIZE[1]/2 + y_new*400)
[x, y] = [x_new, y_new]
pygame.draw.circle(SCREEN, COLOR, (x_display, y_display), 1)
pygame.display.flip()
pygame.time.wait(10)
# Check if the time difference is 60 seconds then game will stop.
if time.time() - timer >= 60:
running = False
pygame.quit()
if __name__ == '__main__':
main()