-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_sway.py
61 lines (50 loc) · 1.71 KB
/
test_sway.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
#!/usr/bin/python
from argparse import ArgumentParser
from sway import Sway
from vector import Vector2d
import random
import copy
import sys
sys.path.append("visual-experiments")
import rectangular_visualizer as visualizer
from OpenGL.GL import *
class Node:
def __init__(self, position):
self.position = position
self._sway = Sway()
def update(self, time_increment):
self._sway.update(time_increment)
def sway(self):
return self._sway.sway
class MovingNodes(visualizer.Visualizer):
def __init__(self, *args):
visualizer.Visualizer.__init__(self, *args)
self.nodes = [Node(self.random_position()) for n in range(10)]
def random_position(self):
return Vector2d(random.uniform(0,1),
random.uniform(0,1))
def render(self):
glEnable(GL_POINT_SMOOTH)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glPointSize(10)
glColor3f(0,0,0)
for node in self.nodes:
node.update(self.time_increment)
self.draw_node(node)
def draw_node(self, node):
glBegin(GL_POINTS)
glVertex2f((node.position.x + node.sway().x) * self.width,
(node.position.y + node.sway().y) * self.height)
glEnd()
glBegin(GL_LINES)
glVertex2f((node.position.x + node.sway().x) * self.width,
(node.position.y + node.sway().y) * self.height)
glVertex2f(node.position.x * self.width,
node.position.y * self.height)
glEnd()
parser = ArgumentParser()
MovingNodes.add_parser_arguments(parser)
options = parser.parse_args()
options.standalone = True
MovingNodes(options).run()