-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgenerate-white-noise.py
executable file
·68 lines (55 loc) · 1.61 KB
/
generate-white-noise.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
#!/usr/bin/env python
# ------------------------------------------------------------------
# Copyright (C) 2013 Michael Aschauer
# ------------------------------------------------------------------
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.s
# ------------------------------------------------------------------
import stitchcode
import numpy
import math
from scipy import interpolate
stepsize_x = 2
stepsize_y = 30
def getDistance(x1, y1, x2, y2):
dx = x1 - x2
dy = y1 - y2
dist = math.sqrt( dx*dx + dy*dy )
return dist
if __name__ == "__main__":
emb = stitchcode.Embroidery()
emb.addStitch(stitchcode.Point(0,0))
last_y = 0;
x=0
for j in range(0, 512):
if j % 1 == 0:
y = numpy.random.normal(0,0.5) * 127
else:
y = 0
d = getDistance(0, last_y, stepsize_y, y)
steps = max(1,int(round( d / stepsize_y)))
yarr = (last_y,y)
xarr = (0,steps+1)
xnew = range(0,steps+1)
f = interpolate.interp1d(xarr,yarr)
ynew = f(xnew)
print steps, y, ynew
if steps == 1:
x += stepsize_x
emb.addStitch(stitchcode.Point(x, y))
print (x,y)
else:
for i in range(1,steps+1):
if ((i == 1) or (i == 2 and stepsize_x < 3)):
x += 1
y = ynew[i]
emb.addStitch(stitchcode.Point(x, y))
last_y = y
print (x,y)
x = x + stepsize_x
emb.addStitch(stitchcode.Point(x,0))
emb.translate_to_origin()
emb.save_as_exp("noise.exp")
emb.save_as_png("noise.png",False)