#define global swap(%1,%2) _temp = %1 : %1 = %2 : %2 = _temp
#module
#deffunc modinit
dim fx,4
dim fy,4
dim dx,4
dim dy,4
dim sort,4
dim nact,4
dim lt,4
dim lb,4
dim is,4
dim ar,4
dim ra,4
return
#deffunc modfrom int,int,int,int,int
mref _wid : wid = _wid
mref x,1 : mref y,2
mref sx,3 : mref sy,4
fx = x,x + sx,x + sx,x
fy = y,y,y + sy,y + sy
return
#deffunc modify val
mref p,48
repeat 4
c = cnt * 2 : cp = c + 1
dx.cnt = p.c : dy.cnt = p.cp
loop
repeat 4
c = cnt + 1 \ 4
if dy.cnt > dy.c {
lt.cnt = c : lb.cnt = cnt
ar.cnt = dy.cnt - dy.c
} else {
lt.cnt = cnt : lb.cnt = c
ar.cnt = dy.c - dy.cnt
}
loop
memcpy sort,dy,16
repeat 3
repeat 3 - cnt
c = cnt + 1
if sort.cnt > sort.c {
swap sort.cnt,sort.c
}
loop
loop
na = 0
dim act,4
sty = sort.0
repeat sort.3 - sort.0
ny = sty + cnt
repeat 4
ls = lt.cnt
le = lb.cnt
if ny == dy.ls {
act.na = cnt
nact.cnt = na
na++
}
a = 0
if ny == dy.le {
na--
c = nact.cnt
d = act.na
act.c = d
nact.d = c
}
loop
repeat na
c = act.cnt
d = lt.c : e = lb.c
ra.c = ny - dy.d
is.cnt = dx.e - dx.d * ra.c / ar.c + dx.d
loop
repeat na - 1
repeat na - 1 - cnt
c = cnt + 1
if is.cnt > is.c {
swap is.cnt,is.c
d = act.cnt : e = act.c
swap act.cnt,act.c
swap nact.d,nact.e
}
loop
loop
repeat na / 2
c = cnt * 2 : d = c + 1
e = act.c : ls = lt.e : le = lb.e
fsx = fx.le - fx.ls * ra.e / ar.e + fx.ls
fsy = fy.le - fy.ls * ra.e / ar.e + fy.ls
e = act.d : ls = lt.e : le = lb.e
fex = fx.le - fx.ls * ra.e / ar.e + fx.ls
fey = fy.le - fy.ls * ra.e / ar.e + fy.ls
len = is.d - is.c
repeat len
pos is.c + cnt,ny
gcopy wid,fex - fsx * cnt / len + fsx,fey - fsy * cnt / len + fsy,1,1
loop
loop
loop
return
#global
buffer 2
dialog "bmp;*.jpg",16
if refstr == "" : end
picload refstr
sizex = winx
sizey = winy
screen 0,400,400
onclick *click
stop
*click
pset mousex,mousey
p.c = mousex,mousey
c + 2
if c = 8 {
modinit
modfrom 2,0,0,sizex,sizey
modify p
onclick 0
}
stop
|