This repository has been archived by the owner on Feb 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
/
main_line.py
executable file
·123 lines (76 loc) · 2.24 KB
/
main_line.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from numpy import pi, cos, sin, linspace, zeros
from numpy.random import random
from modules.growth import spawn, spawn_curl
NMAX = 10**7
SIZE = 10000
ONE = 1./SIZE
STP = ONE*0.02
NEARL = 15*ONE
FARL = 0.235
PROCS = 6
MID = 0.5
LINEWIDTH = 5.*ONE
INIT_NUM = 7
BACK = [1,1,1,1]
FRONT = [0,0,0,0.08]
TWOPI = pi*2.
def main():
from time import time
from itertools import count
from differentialLine import DifferentialLine
from iutils.render import Render
from modules.helpers import print_stats
from modules.show import sandstroke
from modules.show import show
from modules.show import dots
np_coords = zeros(shape=(NMAX,4), dtype='float')
np_vert_coords = zeros(shape=(NMAX,2), dtype='float')
DF = DifferentialLine(NMAX, FARL*2, NEARL, FARL, PROCS)
render = Render(SIZE, BACK, FRONT)
render.ctx.set_source_rgba(*FRONT)
render.ctx.set_line_width(LINEWIDTH)
# angles = sorted(random(INIT_NUM)*TWOPI)
# DF.init_circle_segment(MID,MID,0.2, angles)
## arc
angles = sorted(random(INIT_NUM)*pi*1.5)
xys = []
for a in angles:
x = 0.5 + cos(a)*0.2
y = 0.5 + sin(a)*0.2
xys.append((x,y))
DF.init_line_segment(xys, lock_edges=1)
## vertical line
#yy = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
#xx = MID+0.005*(0.5-random(INIT_NUM))
#xys = []
#for x,y in zip(xx,yy):
#xys.append((x,y))
#DF.init_line_segment(xys, lock_edges=1)
## diagonal line
# yy = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
# xx = sorted(MID + 0.2*(1-2*random(INIT_NUM)))
# xys = []
# for x,y in zip(xx,yy):
# xys.append((x,y))
# DF.init_line_segment(xys, lock_edges=1)
for i in count():
t_start = time()
DF.optimize_position(STP)
spawn_curl(DF,NEARL,0.016)
if i%100==0:
fn = './res/chris_bd_{:04d}.png'.format(i)
else:
fn = None
render.set_front(FRONT)
num = DF.np_get_edges_coordinates(np_coords)
sandstroke(render,np_coords[:num,:],20,fn)
if random()<0.05:
sandstroke(render,np_coords[:num,:],30,None)
vert_num = DF.np_get_vert_coordinates(np_vert_coords)
dots(render,np_vert_coords[:vert_num,:],None)
t_stop = time()
print_stats(i,t_stop-t_start,DF)
if __name__ == '__main__':
main()