-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadversarial_generator.py
63 lines (54 loc) · 1.57 KB
/
adversarial_generator.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
import sys, random
gen = random.randrange(7000, 15000)
gen = 6502
print >>sys.stderr, gen
noise = 4
image = """
.....##.........
....#..#........
....#..#........
....#..#........
.....#..#.......
.....#...#......
..#####...#.....
.#.....#...#....
.#.....#...##...
.######....#.###
#......#...#.###
#......#...#.###
.######....#.###
.#.....#...#.###
..#...#...###...
...#######......
""".strip().split('\n')
x0 = -len(image[0]) / 2
y0 = -len(image) / 2
stars = set()
def gen_star(x, y, noise=False):
while True:
vx = random.randrange(1, 10) * (1 - 2 * random.randrange(2))
vy = random.randrange(1, 10) * (1 - 2 * random.randrange(2))
px = x - vx * gen
py = y - vy * gen
if noise:
vx += random.randrange(1, 10) * (1 - 2 * random.randrange(2))
vy += random.randrange(1, 10) * (1 - 2 * random.randrange(2))
px += random.randrange(-gen/2, gen/2)
py += random.randrange(-gen/2, gen/2)
star = (px, py, vx, vy)
if vx and vy and abs(vx)<=9 and abs(vy)<=9 and abs(px)<=99999 and abs(py)<=99999 and not(star in stars):
return stars.add(star)
for ry, row in enumerate(image):
y = y0 + ry
for rx, cell in enumerate(row):
if cell != '#':
continue
x = x0 + rx
for n in xrange(noise + 1):
gen_star(x, y, n)
stars = list(stars)
random.shuffle(stars)
for star in stars:
print "position=<%6d, %6d> velocity=<%2d, %2d>" % star
s = len(stars) / (noise + 1)
print >>sys.stderr, "%d stars (%d noise, %s real)" % (len(stars), s * noise, s)