/
main.py
104 lines (83 loc) · 2.28 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import sys
import time
import pygame
import random
from render import Render
from point_generator import PointGenerator
#globals
g_width = 1024
g_height = 768
g_time = 0
g_changed = False
def repaint():
global render
global point_generator
render.render(point_generator.getPointList(), pygame.Rect((g_width-g_height)/2, 0, g_height, g_height), 10, point_generator.x_func_idx, point_generator.y_func_idx, point_generator.count)
def ping(changed):
global g_time
global g_changed
g_changed = changed
g_time = time.clock()
def restart():
global render
global point_generator
point_generator = PointGenerator()
point_generator.changeXFunc()
point_generator.changeYFunc()
if random.random() > 0.5:
render.swapColors();
repaint()
#main setup
render = Render(g_width, g_height)
pygame.mouse.set_visible(False)
pygame.display.toggle_fullscreen()
#create and draw first polyline
restart()
#main loop
while True:
try:
#check idle time
if time.clock() - g_time > 60:
if g_changed:
render.save()
restart()
#render.credits()
ping(False)
for event in pygame.event.get():
#update idle time
ping(True)
#key input
if event.type == pygame.KEYUP:
if event.key == pygame.K_f:
pygame.display.toggle_fullscreen()
if event.key == pygame.K_ESCAPE:
sys.exit(0)
#if event.type == pygame.MOUSEMOTION:
#check mouse inputs
if event.type == pygame.MOUSEBUTTONDOWN:
point_generator.seeds = pygame.mouse.get_rel()
if event.dict['button'] == 1:
#left mouse button
point_generator.changeXFunc()
repaint()
elif event.dict['button'] == 2:
#mouse wheelbutton
render.swapColors()
repaint()
elif event.dict['button'] == 3:
#right mouse button
point_generator.changeYFunc()
repaint()
elif event.dict['button'] == 4:
#mouse wheel up
point_generator.incCount()
repaint()
elif event.dict['button'] == 5:
#mouse wheel down
point_generator.decCount()
repaint()
if event.type == pygame.QUIT:
sys.exit(0)
except Exception as e:
print e
restart()