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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
############################################################################
#
# File: offtiler.icn
#
# Subject: Program to tile images with offset
#
# Author: Ralph E. Griswold
#
# Date: March 14, 1998
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program produces drop repeats and brick patterns.
#
############################################################################
#
# Requires: Version 9 graphics
#
############################################################################
#
# Links: io, vsetup
#
############################################################################
link io
link vsetup
global direction
global factor
global height
global subject
global target
global vidgets
global width
procedure main()
vidgets := ui()
direction := "vertical"
factor := 1
GetEvents(vidgets["root"], , shortcuts)
end
procedure file_cb(vidget, value)
case value[1] of {
"open @O" : open_image()
"save @S" : save_tile()
"quit @Q" : exit()
}
return
end
procedure parameter_cb(vidget, value)
case value[1] of {
"direction @D" : set_direction()
"factor @F" : set_factor()
}
return
end
procedure tile_cb()
local incr, i, j, offset
if /subject then {
Notice("No subject image.")
fail
}
WClose(\target)
target := WOpen("label=offset tile", "size=" || (width * factor) || "," ||
(height * factor)) | {
Notice("Cannot open target window.")
fail
}
Raise()
case direction of {
"vertical" : {
incr := height / factor
every i := -1 to factor do { # columns
offset := i * incr
every j := -1 to factor do { # rows
CopyArea(subject, target, 0, 0, width, height, i * width,
j * height + offset)
}
}
}
"horizontal" : {
incr := width / factor
every i := -1 to factor do { # rows
offset := i * incr
every j := -1 to factor do { # columns
CopyArea(subject, target, 0, 0, width, height,
j * width + offset, i * height)
}
}
}
}
return
end
procedure set_direction()
repeat {
if SelectDialog("Direction", ["vertical", "horizontal"], direction) ==
"Cancel" then fail
direction := dialog_value
check_parameters() | next
return
}
end
procedure set_factor()
repeat {
if TextDialog("Offset factor", , factor) == "Cancel" then fail
factor := (0 < integer(dialog_value[1])) | {
Notice("Invalid factor specification.")
next
}
check_parameters() | next
return
}
end
procedure check_parameters()
case direction of {
"vertical" : {
if (height % factor) ~= 0 then {
Notice("Factor does not evenly divide height.")
fail
}
if factor >= height then {
Notice("Factor too large.")
fail
}
}
"horizontal" : {
if (width % factor) ~= 0 then {
Notice("Factor does not evenly divide width.")
fail
}
if factor >= width then {
Notice("Factor too large.")
fail
}
}
}
return
end
procedure shortcuts(e)
if &meta then case map(e) of {
"d" : set_direction()
"f" : set_factor()
"o" : open_image()
"q" : exit()
"s" : save_tile()
"t" : tile_cb()
}
return
end
procedure open_image()
repeat {
if OpenDialog("Open image:") == "Cancel" then fail
WClose(\subject)
subject := WOpen("label=" || dialog_value, "image=" || dialog_value) | {
Notice("Cannot open image.")
next
}
width := WAttrib(subject, "width")
height := WAttrib(subject, "height")
factor := 1
Raise()
return
}
end
procedure save_tile()
local file
repeat {
if SaveDialog("Save tile:") ~== "Yes" then fail
file := dialog_value
if exists(file) then {
if TextDialog("Overwrite existing file?") == "Cancel" then next
}
WriteImage(target, file) | {
Notice("Cannot write image.")
next
}
return
}
end
#===<<vib:begin>>=== modify using vib; do not remove this marker line
procedure ui_atts()
return ["size=200,165", "bg=pale gray"]
end
procedure ui(win, cbk)
return vsetup(win, cbk,
[":Sizer:::0,0,200,165:",],
["file:Menu:pull::0,0,36,21:File",file_cb,
["open @O","save @S","quit @Q"]],
["line1:Line:::0,23,200,23:",],
["parameters:Menu:pull::37,0,78,21:Parameters",parameter_cb,
["direction @D","factor @F"]],
["tile:Button:regular::12,36,35,20:tile",tile_cb],
)
end
#===<<vib:end>>=== end of section maintained by vib
|