-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bot.rb
executable file
·423 lines (388 loc) · 9.22 KB
/
Bot.rb
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
$LOAD_PATH << "C:\cygwin64\lib\ruby\mathn\2.3.0"
require 'complex'
$rimmer = 0.1
#zer introduces "z"
#uno bitwidth ducked
#duo
#tri
#qua
#bot bitwidth declared composition?
#top bitwifth decreased
class Bo #also _is_ an affine
depth = 0
end
class Duo < Bo
x=0
y=0
content = [] #composition
affines = []
end
class Trio < Duo
r=0
end
class Tetro < Trio
angola=45
#initiate also with Duo, Duo for bounds instance cut
end
class Bot
$bitwidth = 0.125
$halfwidth = $bitwidth/2
TIERATE = 0.12
@@lipp = 0.05
@@pentrate = 30
@@feedrate = 40
@@numero = 0
@@deepana = -0.25
def initialize(starx, stary)
@heighchub = @heigh / 2.0
@duxulate =Integer(@depth / TIERATE)
@starx = starx
@stary = stary
@curxo = starx
printf"F40\n"
end
def retrax(z)
printf "G0 Z%5.5f\n",z
end
def retract
retrax(0.1)
end
def penetrate(z)
printf "G1 Z%5.5f\n", z #@@pentrate
end
def cutoPoint(x,y)
printf "G1 X%5.5f Y%5.5f\n", x, y #@@feedrate
end
def skimtoPoint(x,y,z)
retrax(z)
printf "G0 X%5.5f Y%5.5f\n", x, y
end
def gotoPoint(x,y)
skimtoPoint(x,y,0.1)
end
def dwellus(tparm)
printf "G4 P%5.5f \n",tparm
end
def drillus(x,y,zstart,zdepth)
skimtoPoint(x,y,zstart+0.1)
penetrate(zdepth)
#boom!dwellus(0.5)
end
def drawzframe(minx,miny,maxx,maxy)
#dwellus(0.1)
if minx > maxx then minx = maxx = (minx+maxx)/2 end
if miny > maxy then miny = maxy = (miny+maxy)/2 end
cutoPoint(minx,miny)
cutoPoint(minx,maxy)
cutoPoint(maxx,maxy)
cutoPoint(maxx,miny)
cutoPoint(minx,miny)
end
def drawzsquare(minx,miny,maxx,maxy)
minx += $halfwidth
miny += $halfwidth
maxx -= $halfwidth
maxy -= $halfwidth
drawzframe(minx,miny,maxx,maxy)
while (minx < maxx) and (miny < maxy)
minx += $bitwidth
miny += $bitwidth
maxx -= $bitwidth
maxy -= $bitwidth
drawzframe(minx,miny,maxx,maxy)
end
midx = (minx + maxx) / 2
#cutoPoint(midx,maxy)
#cutoPoint(midx,miny)
end
def dux(starx,stary,dendx,dendy,zstart,zdepth,step)
incro = (Float(zdepth-zstart) / Float(step))
skimtoPoint(starx,stary,zstart+0.1)
for i in 1..step do
penetrate(zstart + (incro * i))
if (i.divmod(2)[1] != 0) then
cutoPoint(dendx, dendy) else
cutoPoint(starx, stary) end
end
end
def box(minx,miny,maxx,maxy,zstart,zdepth,step)
incro = (Float(zdepth-zstart) / Float(step))
skimtoPoint(minx+$halfwidth,miny+$halfwidth,zstart+0.1)
for i in 1..step do
penetrate(zstart + (incro * i))
drawzsquare(minx,miny,maxx,maxy)
end
end
#hacked to change random bitsiwth fiox with classvar
def randdrawzsquare(minx,miny,maxx,maxy,bronk)
minx += $halfwidth
miny += $halfwidth
maxx -= $halfwidth
maxy -= $halfwidth
drawzframe(minx,miny,maxx,maxy)
while (minx < maxx) and (miny < maxy)
#drawzframe(minx,miny,maxx,maxy)
minx += bronk
miny += bronk
maxx -= bronk
maxy -= bronk
drawzframe(minx,miny,maxx,maxy)
end
midx = (minx + maxx) / 2
#cutoPoint(midx,maxy)
#cutoPoint(midx,miny)
end
def randbox(minx,miny,maxx,maxy,zstart,zdepth,step)
incro = (Float(zdepth-zstart) / Float(step))
skimtoPoint(minx+$halfwidth,miny+$halfwidth,zstart+0.1)
for i in 1..step do
penetrate(zstart + (incro * i))
randdrawzsquare(minx,miny,maxx,maxy,Float(rand(6))/18.0 + 1.0/8.0)
end
end
def bronx(minx,miny,maxx,maxy,zstart,zdepth,step, bron)
incro = (Float(zdepth-zstart) / Float(step))
skimtoPoint(minx+$halfwidth,miny+$halfwidth,zstart+0.1)
for i in 1..step do
penetrate(zstart + (incro * i))
randdrawzsquare(minx,miny,maxx,maxy,bron)
end
end
def fox(minx,miny,maxx,maxy,zstart,zdepth,step)
incro = (Float(zdepth-zstart) / Float(step))
skimtoPoint(minx+$halfwidth,miny+$halfwidth,zstart+0.1)
minx += $halfwidth
miny += $halfwidth
maxx -= $halfwidth
maxy -= $halfwidth
for i in 1..step do
penetrate(zstart + (incro * i))
drawzframe(minx,miny,maxx,maxy)
end
end
def arc(x,y,z,r)
if $DEBUG then
printf "G2 X%5.5f Y%5.5f I%5.5f J%5.5f Z%5.5f\n",
x+r, y, x, y, z
else
printf "G2 X%5.5f Y%5.5f I%5.5f J%5.5f Z%5.5f\n",
x+r, y, r, 0, z
end
end
def pipe(x,y,r,s,e)
r -= $halfwidth
skimtoPoint(x+r,y,0.1)
penetrate(s)
z = s
incro = 0.125/2.0
while z > (e - incro) do
z -= incro
ee = z
if (z < e) then ee = e-0.001 end
arc(x,y,ee,-r)
z -= incro
ee = z
if (z < e) then ee = e-0.001 end
arc(x,y,ee,r)
end
if $DEBUG then arc(x,y,e-0.002,r) end
end
NUMSEGS = 32
@@twiddle = 0.001
def drawzcirque(x,y,r,z)
cutoPoint(x+r,y)
arc(x,y,z-@@twiddle,-r)
arc(x,y,z-@@twiddle,r)
@@twiddle=@@twiddle*(-1.0)
end
def drawzdisque(x,y,r,z)
r -= $halfwidth
while r > 0
drawzcirque(x,y,r,z)
r -= $bitwidth
end
end
def tubo(x,y,r,zstart,zdepth,step)
incro = (Float(zdepth-zstart) / Float(step))
skimtoPoint(x,y,zstart+0.1)
for i in 1..step do
penetrate(zstart + (incro * i))
drawzdisque(x,y,r,zstart + (incro * i))
end
end
def grancirque(x,y,xr,yr)
xr -= $halfwidth
yr -= $halfwidth
numsegs = Integer(xr*32+1)
for i in 0..NUMSEGS do
xx = xr * Math.sin(2 * i * Math::PI / NUMSEGS)
yy = yr * Math.cos(2 * i * Math::PI / NUMSEGS)
cutoPoint(x+xx,y+yy)
end
end
def grantubo(x,y,xr,yr,zstart,zdepth,step)
incro = (Float(zdepth-zstart) / Float(step))
skimtoPoint(x,y,zstart+0.1)
for i in 1..step do
penetrate(zstart + (incro * i))
grancirque(x,y,xr,yr)
end
end
def flip() end
def duxo()
@curxo += $halfwidth
dux(@curxo, @stary-getBrot, @curxo, @stary+getBrot, 0, 0-@depth, @duxulate)
@curxo += $halfwidth
return @curxo
end
def duxong(pranska)
incro = (Float(@depth) / Float(@duxulate))
skimtoPoint(pranska[0][0],pranska[0][1],0.1)
for i in 1..@duxulate do
penetrate(0-(incro * i))
if (i.divmod(2)[1] != 0) then
pranska.each {|x| cutoPoint(x[0],x[1])} else
pranska.reverse.each {|x| cutoPoint(x[0],x[1])}
end
end
end
def getBrot()
return @heighchub + $halfwidth + @@lipp
end
def getTopPranska()
pranska = [[@starx,@stary+getBrot], [@curxo,@stary+getBrot]]
end
def getBotPranska()
pranska = [[@starx,@stary-getBrot], [@curxo,@stary-getBrot]]
end
def ducatop()
brot = getBrot()
dux(@starx,@stary+brot,@curxo,@stary+brot,0,0-@depth,@duxulate)
end
def ducabot()
brot = getBrot()
dux(@starx,@stary-brot,@curxo,@stary-brot,0,0-@depth,@duxulate)
end
def numerize
end
def numerset(t)
@@numero = t
end
def getWido
end
end
def indostutterat(clasz)
xarg = 1
unless ARGV[1].nil? then xarg = Integer(ARGV[1]) end
browblank = []
mystuff = clasz.new(0,0)
mystuff = clasz.new(mystuff.duxo(), 0)
for j in 1..xarg do
browblank.push(mystuff)
mystuff.boxo()
mystuff = clasz.new(mystuff.duxo(),0)
end
browblank.reverse.each {|y| y.ducabot}
browblank.each {|y| y.ducatop}
printf "G0 Z0.5\n"
printf "G0 X0 Y0 \n"
end
def oldestutterat(clasz)
xarg = yarg = 1
unless ARGV[0].nil? then yarg = Integer(ARGV[0]) end
unless ARGV[1].nil? then xarg = Integer(ARGV[1]) end
if yarg == 0 then return indostutterat(clasz) end
curyo = clasz.new(0,0).getBrot #* (yarg-1)
curyop = curyo + 0.05 + (2*curyo*(yarg-1)) + (yarg*$rimmer)
curyob = 0 - curyop
rowse = []
toprowse = []
botrowse = []
for i in 1..yarg do
curxo = 0
trowblank = []
mystuff = clasz.new(curxo,curyop)
mystuff = clasz.new(mystuff.duxo(), curyop)
if i == 1 then mystuff.numerize end
for j in 1..xarg do
trowblank.push(mystuff)
mystuff.boxo()
mystuff = clasz.new(mystuff.duxo(), curyop)
end
#toprowse.push(rowblank)
browblank = []
mystuff = clasz.new(curxo,-curyop)
mystuff = clasz.new(mystuff.duxo(),-curyop)
for j in 1..xarg do
browblank.push(mystuff)
mystuff.boxo()
mystuff = clasz.new(mystuff.duxo(),-curyop)
end
trowblank.each {|y| y.ducatop}
trowblank.reverse.each {|y| y.ducabot}
browblank.reverse.each {|y| y.ducabot}
browblank.each {|y| y.ducatop}
#botrowse.push(rowblank)
curyop -= mystuff.getBrot
curyop -= mystuff.getBrot
curyop -= $rimmer
end
printf "G0 Z0.5\n"
printf "G0 X0 Y0 \n"
#toprowse.reverse.each {|x|
# x.each {|y| y.ducatop}
# x.reverse.each {|y| y.ducabot}
#}
#botrowse.reverse.each {|x|
# x.reverse.each {|y| y.ducabot}
# x.each {|y| y.ducatop}
#}
end
$rimmer = 0.01
def stutterat(clasz)
xarg = yarg = 1
unless ARGV[0].nil? then yarg = Integer(ARGV[0]) end
unless ARGV[1].nil? then xarg = Integer(ARGV[1]) end
broth = clasz.new(0,0).getBrot + $rimmer
curyop = (yarg-1)*broth
curxo = 0
mystuff = clasz.new(curxo,0)
for i in 1..xarg do
if i == 1 then mystuff.numerize end
curyo = curyop
for j in 1..yarg do
mystuff = clasz.new(curxo,curyo)
mystuff.boxo()
mystuff.ducabot()
curyo -= broth*2
end
curxo = mystuff.duxo() + $rimmer
end
printf "G0 Z0.5\n"
printf "G0 X0 Y0 \n"
return curxo
end
def nummerat(clasz,num)
xarg = yarg = 1
unless ARGV[0].nil? then yarg = Integer(ARGV[0]) end
unless ARGV[1].nil? then xarg = Integer(ARGV[1]) end
broth = clasz.new(0,0).getBrot + $rimmer
curyop = (yarg-1)*broth
curxo = 0
mystuff = clasz.new(curxo,0)
#curxo = mystuff.duxo()
for i in 1..xarg do
curyo = curyop
for j in 1..yarg do
mystuff = clasz.new(curxo,curyo)
mystuff.numerset(num)
mystuff.boxo()
mystuff.ducabot()
curyo -= broth*2
end
curxo = mystuff.duxo() + $rimmer
end
printf "G0 Z0.5\n"
printf "G0 X0 Y0 \n"
return curxo
end