-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparticleDataStructures.py
More file actions
99 lines (78 loc) · 2.41 KB
/
particleDataStructures.py
File metadata and controls
99 lines (78 loc) · 2.41 KB
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
#!/usr/bin/env python
# Some suitable functions and data structures for drawing a map and particles
import time
import random
import math
# A Canvas class for drawing a map and particles:
# - it takes care of a proper scaling and coordinate transformation between
# the map frame of reference (in cm) and the display (in pixels)
class Canvas:
def __init__(self,map_size=210):
self.map_size = map_size; # in cm;
self.canvas_size = 768; # in pixels;
self.margin = 0.05*map_size;
self.scale = self.canvas_size/(map_size+2*self.margin);
def drawLine(self,line):
x1 = self.__screenX(line[0]);
y1 = self.__screenY(line[1]);
x2 = self.__screenX(line[2]);
y2 = self.__screenY(line[3]);
print "drawLine:" + str((x1,y1,x2,y2))
def drawParticles(self,data):
display = [(self.__screenX(d[0]),self.__screenY(d[1])) + d[2:] for d in data];
print "drawParticles:" + str(display);
def __screenX(self,x):
return (x + self.margin)*self.scale
def __screenY(self,y):
return (self.map_size + self.margin - y)*self.scale
# A Map class containing walls
class Map:
def __init__(self, _canvas):
self.walls = [];
self.canvas = _canvas;
def add_wall(self,wall):
self.walls.append(wall);
def clear(self):
self.walls = [];
def draw(self):
for wall in self.walls:
self.canvas.drawLine(wall);
# Simple Particles set
class Particles:
def __init__(self, _canvas):
self.n = 100;
self.data = [];
self.canvas = _canvas;
def update(self, particleSet):
self.data = particleSet;
def draw(self):
self.canvas.drawParticles(self.data);
#canvas = # global canvas we are going to draw on
'''
mymap = Map();
# Definitions of walls
# a: O to A
# b: A to B
# c: C to D
# d: D to E
# e: E to F
# f: F to G
# g: G to H
# h: H to O
mymap.add_wall((0,0,0,168)); # a
mymap.add_wall((0,168,84,168)); # b
mymap.add_wall((84,126,84,210)); # c
mymap.add_wall((84,210,168,210)); # d
mymap.add_wall((168,210,168,84)); # e
mymap.add_wall((168,84,210,84)); # f
mymap.add_wall((210,84,210,0)); # g
mymap.add_wall((210,0,0,0)); # h
mymap.draw();
#particles = Particles();
#t = 0;
#while True:
# particles.update();
# particles.draw();
# t += 0.05;
#time.sleep(0.05);
'''