This repository has been archived by the owner on Apr 16, 2019. It is now read-only.
/
main-bg.py
executable file
·137 lines (107 loc) · 2.3 KB
/
main-bg.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from numpy import pi
from numpy import array
from numpy import linspace
from numpy.random import random
from numpy.random import randint
from numpy import zeros
from numpy import arange
from numpy import column_stack
from numpy import cos
from numpy import sin
from modules.helpers import get_img_as_rgb_array
BG = [1,1,1,1]
BACK = [1,1,1,1]
FRONT = [0,0,0,0.5]
TWOPI = 2.0*pi
IMGNAME = './img/check-bw.png'
img = get_img_as_rgb_array(IMGNAME)
SIZE = img.shape[0]
PIX = 1.0/SIZE
CNUM = 50
INUM = 4000
STP = 0.000001
GRID_X = SIZE*20
# def f():
# x = random()
# y = random()
# while True:
# yield array([[x,y]])
# def spline_iterator():
# from modules.sandSpline import SandSpline
#
# splines = []
# for _ in range(CNUM):
# guide = f()
#
# pnum = randint(10, 100)
# crad = 0.01 + 0.1*random()
#
# a = random()*TWOPI + linspace(0, TWOPI, pnum)
# path = column_stack((cos(a), sin(a))) * crad
#
# scale = arange(pnum).astype('float')*STP
#
# s = SandSpline(
# guide,
# path,
# INUM,
# scale
# )
# splines.append(s)
#
# itt = 0
# while True:
# for s in splines:
# xy = next(s)
# itt += 1
# yield itt, xy
def f():
for x in linspace(0, 1.0, GRID_X):
yield array([[x,0]])
def spline_iterator():
from modules.sandSpline import SandSpline
splines = []
pnum = 10
guide = f()
y = linspace(0,1.0, pnum)
x = zeros(pnum,'float')
path = column_stack([x,y])
scale = arange(pnum).astype('float')*STP
s = SandSpline(
guide,
path,
INUM,
scale
)
splines.append(s)
itt = 0
while True:
for s in splines:
xy = next(s)
itt += 1
yield itt, xy
def main():
import sys, traceback
from fn import Fn
from sand import Sand
sand = Sand(SIZE)
sand.set_bg_from_rgb_array(img)
sand.set_rgba(FRONT)
fn = Fn(prefix='./res/', postfix='.png')
si = spline_iterator()
while True:
try:
itt, xy = next(si)
# sand.distort_dots_swap(xy)
sand.distort_dots_wind(xy)
if not itt%5000:
print(itt)
sand.write_to_png(fn.name())
except Exception:
sand.write_to_png(fn.name())
traceback.print_exc(file=sys.stdout)
return
if __name__ == '__main__':
main()