forked from chandabindu/twobounce
-
Notifications
You must be signed in to change notification settings - Fork 1
/
drawlight.py
131 lines (99 loc) · 4.11 KB
/
drawlight.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/python
from gi.repository import Gtk
import cairo
import math
import poly
class drawlight(Gtk.Window):
def __init__(self, polys):
super(drawlight, self).__init__()
# self.winw = 1024.0
# self.winh = 768.0
self.winw = 1000.0
self.winh = 800.0
self.zmin = -4.0
# self.zmax = 6.0
self.zmax = 30.0
# self.zmax = 10.0
self.yscale = 8.0
#self.yscale = 1.0
self.init_ui()
self.polys = polys
def init_ui(self):
darea = Gtk.DrawingArea()
darea.connect("draw", self.on_draw)
self.add(darea)
self.set_title("Moller Collimators")
self.resize(self.winw, self.winh)
self.set_position(Gtk.WindowPosition.CENTER)
self.connect("delete-event", Gtk.main_quit)
self.show_all()
def on_draw(self, wid, cr):
cr.set_antialias(cairo.ANTIALIAS_NONE)
cr.set_source_rgb(0.0, 0.0, 0.0)
cr.paint()
w, h = self.get_size()
scaleval = self.winw/(self.zmax-self.zmin)
cr.scale(scaleval, -scaleval)
cr.translate( -self.zmin, -self.winh/scaleval/2)
for apoly in self.polys:
for aface in apoly.faces:
# print "drawing ", aface.v1[0], aface.v1[1], " -> ", aface.v2[0], aface.v2[1]
if not aface.isEthereal:
cr.move_to( aface.v1[0], aface.v1[1]*self.yscale )
cr.line_to( aface.v2[0], aface.v2[1]*self.yscale )
cr.set_line_width(1.0/scaleval)
cr.set_source_rgb(0.5, 0.5, 0.5)
cr.stroke()
# Lit by secondaries
for lface in aface.getlitfaces(2):
cr.move_to( lface.v1[0], lface.v1[1]*self.yscale )
cr.line_to( lface.v2[0], lface.v2[1]*self.yscale )
if lface.isDetector:
cr.set_line_width(4.0/scaleval)
else:
cr.set_line_width(2.0/scaleval)
# cr.set_source_rgb(0.7, 0.5, 0.1)
cr.set_source_rgb(0.1, 0.5, 0.1)
cr.stroke()
# Lit by primaries
for lface in aface.getlitfaces():
cr.move_to( lface.v1[0], lface.v1[1]*self.yscale )
cr.line_to( lface.v2[0], lface.v2[1]*self.yscale )
if lface.isDetector:
cr.set_line_width(4.0/scaleval)
else:
cr.set_line_width(2.0/scaleval)
cr.set_source_rgb(1.0, 0.0, 0.0)
cr.stroke()
for lface in aface.getlitfaces(3):
cr.move_to( lface.v1[0], lface.v1[1]*self.yscale )
cr.line_to( lface.v2[0], lface.v2[1]*self.yscale )
cr.set_line_width(3.0/scaleval)
cr.set_source_rgb(1.0, 0.0, 1.0)
cr.stroke()
#self.get_picture()
def get_picture(self):
drawable = self.movie_window.window
colormap = drawable.get_colormap()
pixbuf = Gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, 0, 8, *drawable.get_size())
pixbuf = pixbuf.get_from_drawable(drawable, colormap, 0,0,0,0, *drawable.get_size())
pixbuf.save(r'somefile.png', 'png')
"""
# Pixel by pixel stuff
cr.set_line_width(1.0/scaleval)
height = self.winh*(self.zmax-self.zmin)/self.winw
cr.set_source_rgba(0.0, 0.0, 1.0, 1.0)
for apoly in self.polys:
for xidx in range(int(self.winw)):
for yidx in range(int(self.winh)):
xval = self.zmin + xidx*(self.zmax-self.zmin)/self.winw;
yval = -height/2 + yidx*height/self.winh;
cr.move_to( xval, yval )
cr.line_to( xval, yval + 1.0/scaleval)
cr.stroke()
"""
def main():
app = drawlight()
Gtk.main()
if __name__ == "__main__":
main()