-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ua
100 lines (89 loc) · 1.98 KB
/
main.ua
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
# Experimental!
Dim ← 256_256
Seed ← 0
Sigma ← 1.9
Initial ← 0.1
N ← /×Dim
# Energy map of single pixel
Energy ← ↻¯⊙comptime(
°⍉⇡Dim
/+×.-⌵⤚-÷2Dim # toroidal distance
ⁿ⊙e¯÷×2×.Sigma # gaussian
)
# Build energy map
EMap ← ×√N◌°ℂ⍜(
⍉fft⍉fft
| ×comptime(⍉fft⍉fft Energy 0_0)
)
Argmax ← ⊢⊚=/↥⊸♭
Argmin ← ⊢⊚=/↧⊸♭
FormatTime ← (
⊙"hms" [⌊⊃÷◿60 ⊓⌊⁅⊃÷◿60]
⍚(⨬$"__"⋅⋅""⊸=0)
/◇(⊂⊂)@\s ▽⊸≡≠□""
)
# initial binary pattern
&p"Start"
⍜now(
<Initial↯Dim[◌⍥genN Seed]
⊃(∘|÷⊙1¬|EMap)
⊙◌⍥(
◡(Argmax ×⊙⋅∘)
⊃(⍜⊡⋅0|⍜⊡⋅1 ⊙⋅∘|-Energy ⊙⋅⋅∘)
◡(Argmin ×⋅⊙∘)
⊃(⍜⊡⋅1|⍜⊡⋅∞ ⊙⋅∘|+Energy ⊙⋅⋅∘)
)∞
)
# Phase 1 - make dither array (ordered binary pattern)
# ? binary pattern, energy map
&p$"Phase 1 - _"FormatTime
⍜now(
⧻⊸⊚
⊃(
⋅⊙∘
| ⋅⋅⊙°0 ⍥(
Argmax ◡×
⊃(
⍜⊡⋅0 # remove the tightest cluster
| -Energy ⊙⋅∘ # subtract energy
| ⍜⊡⋅∘ ⊙⋅⋅⊙⟜(-1) # update indices
)
) ⤚⊙⊙⊙(↯Dim0)
| +1
)
)
# Phase 2 - fill voids until 50% full
# ? binary pattern, energy map, dither array, index
&p$"Phase 2 - _"FormatTime
⍜now(
-⊙(⌊÷2N) ⧻⊸⊚ # iteration count
⍜⊙(÷⊙1¬)⍥(
Argmin ◡×
⊃(
⍜⊡⋅∞
| +Energy ⊙⋅∘
| ⍜⊡⋅∘ ⊙⋅⋅⊙⟜(+1)
)
)
)
# Phase 3 - fill all clusters of zeroes
# ? binary pattern, energy map, dither array, index
&p$"Phase 3 - _"FormatTime
⍜now(
⊃(
-⊙N⧻⊚ # iteration count
| ⟜EMap⊙◌ ¬ # flip binary pattern
)
⋅⋅⊙(°1= +1N) ⍥(
Argmax ◡×
⊃(
⍜⊡⋅0
| -Energy ⊙⋅∘
| ⍜⊡⋅∘ ⊙⋅⋅⊙⟜(+1)
)
)
÷N-1
)
&p$"Writing - _"FormatTime
&fwa $"./_x_.png"°⊟Dim img "png"
&p"Done"