This repository has been archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmain.py
executable file
·152 lines (105 loc) · 2.9 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/python3
# -*- coding: utf-8 -*-
BACK = [1,1,1,1]
FRONT = [0,0,0,0.8]
LIGHT = [0,0,0,0.2]
CYAN = [0,0.5,0.5,0.2]
BLUE = [0,0,1,0.3]
NMAX = 10**6
SIZE = 1200
ONE = 1./SIZE
LINEWIDTH = ONE*1.1
INIT_NUM = 20000
INIT_RAD = 0.45
SOURCE_DST = 2.0*ONE
FRAC_DOT = 0.85
FRAC_DST = 100.*ONE
FRAC_STP = ONE*2
FRAC_SPD = 1.0
FRAC_DIMINISH = 0.997
FRAC_SPAWN_DIMINISH = 0.9
SPAWN_ANGLE = 2.0
SPAWN_FACTOR = 0.2
def show(render,fractures):
sources = fractures.sources
alive_fractures = fractures.alive_fractures
dead_fractures = fractures.dead_fractures
def draw_sources():
for i,s in enumerate(sources):
if i not in fractures.visited:
render.circle(*s, r=4*ONE, fill=True)
def draw_lines(fracs):
for frac in fracs:
start = frac.inds[0]
render.ctx.move_to(*sources[start,:])
for c in frac.inds[1:]:
render.ctx.line_to(*sources[c,:])
render.ctx.stroke()
render.clear_canvas()
# render.ctx.set_source_rgba(*LIGHT)
# draw_sources()
render.ctx.set_source_rgba(*LIGHT)
render.set_line_width(3*LINEWIDTH)
draw_lines(alive_fractures+dead_fractures)
render.ctx.set_source_rgba(*FRONT)
render.set_line_width(LINEWIDTH)
draw_lines(alive_fractures+dead_fractures)
# for f in alive_fractures:
# for s in sources[f.inds,:]:
# render.circle(*s, r=2*ONE, fill=False)
def random_uniform_circle(rad, num):
from numpy.random import random
from numpy.linalg import norm
from numpy import array
while True:
xy = 0.5-random(size=2)
if norm(xy)>1.0:
continue
r = array([0.5]*2)+xy*rad
return r
def main():
from iutils.render import Animate
from modules.fracture import Fractures
# from dddUtils.ioOBJ import export_2d as export
from fn import Fn
fn = Fn(prefix='./res/',postfix='.2obj')
F = Fractures(
INIT_NUM,
INIT_RAD,
SOURCE_DST,
FRAC_DOT,
FRAC_DST,
FRAC_STP,
FRAC_SPD,
FRAC_DIMINISH,
FRAC_SPAWN_DIMINISH,
domain = 'rect'
)
print(F.sources.shape)
# uniform square distribution
from numpy.random import random
for _ in range(5):
F.blow(2, random(size=2))
# uniform circular distribution
# for _ in xrange(5):
# F.blow(3, random_uniform_circle(INIT_RAD, num=1))
def wrap(render):
if not F.i % 20:
show(render,F)
# vertices, paths = F.get_vertices_and_paths()
# export('fractures', fn.name(), vertices, lines=paths)
render.write_to_png(fn.name()+'.png')
F.print_stats()
res = F.step(dbg=False)
n = F.spawn_front(factor=SPAWN_FACTOR, angle=SPAWN_ANGLE)
print('spawned: {:d}'.format(n))
# fn = './asdf_{:04d}.png'.format(F.i)
# render.write_to_png(fn)
# if not res:
# vertices, paths = F.get_vertices_and_paths()
# export('fractures', fn.name(), vertices, lines=paths)
return res
render = Animate(SIZE, BACK, FRONT, wrap)
render.start()
if __name__ == '__main__':
main()