Code: Select all
' mirror an image or the screen (img=0)
' horizontal or vertical of course you can combine different calls
' e.g. step 1 vertical step 2 horizontal, step 3 vertical ...
' I'm using only GET and PUT so you can use XOR,PSET,ALPHA ...
sub Mirror(byval img as any ptr=0, byval iHorizontal as integer=1)
static as integer oWidth=0,oHeight=0,oHorizontal=0
static as any ptr imgA=0,imgB=0
dim as integer iWidth=any,iHeight=any
dim as integer xSize=any,ySize=any,xStart=any,yStart,xStep=any,yStep=any
dim as integer x1=any,x2=any,y1=any,y2=any,iStart=any,iEnd=any
if img=0 then ' screen
if ScreenPtr()=0 then exit sub
ScreenInfo(iWidth,iHeight)
else ' image
if ImageInfo(img,iWidth,iHeight) then exit sub
end if
if iHorizontal then iHorizontal=1
' realloc images only if the resolution or the mirror axis are changed !
if iWidth<>oWidth or iHeight<>oHeight or oHorizontal<>iHorizontal then
oWidth = iWidth : oHeight = iHeight : oHorizontal = iHorizontal
if iHorizontal then
xSize=iWidth : ySize=1
else
xSize=1: ySize=iHeight
end if
if ImgA then ImageDestroy ImgA:ImgA=0
if ImgB then ImageDestroy ImgB:ImgB=0
imgA=imageCreate(xSize,ySize)
imgB=imageCreate(xSize,ySize)
end if
' now the magic :lol:
xSize-=1 : ySize-=1
if iHorizontal then
x1=0:x2=0:y1=0:y2=iHeight-1 : xStep=0: yStep=1 : iStart=0:iEnd=iHeight-1
else
x1=0:x2=iWidth-1:y1=0:y2=0 : xStep=1: yStep=0 : iStart=0:iEnd=iWidth-1
end if
while iStart<=iEnd
Get img,(x1,y1)-step(xSize,ySize), imgA
Get img,(x2,y2)-step(xSize,ySize), imgB
Put img,(x1,y1),imgB,pset
Put img,(x2,y2),imgA,pset
x1+=xStep : x2-=xStep
y1+=yStep : y2-=yStep
iStart+=1 : iEnd-=1
wend
end sub
screenres 640,480,8,2
'screenres 640,480,16,2
'screenres 640,480,32,2
screenset 1,0
dim as integer w,h
screeninfo w,h
w-=1 : h-=1
for i as integer= 1 to 10
if (i and 1=1) then
circle (rnd*w,rnd*h),1+h*0.24,culng(2^31*rnd()),,,,F
else
circle (rnd*w,rnd*h),1+h*0.24,culng(2^31*rnd())
end if
if (i and 1=1) then
line (rnd*w,rnd*h)-(rnd*w,rnd*h),culng(2^31*rnd()),BF
else
line (rnd*w,rnd*h)-(rnd*w,rnd*h),culng(2^31*rnd())
end if
next
draw string (8 ,8 ), "Top Left" ,culng(2^31*rnd())
draw string (w-10*8,8 ), "Top Right" ,culng(2^31*rnd())
draw string (w-13*8,h-16), "Bottom Right",culng(2^31*rnd())
draw string (8 ,h-16), "Bottom Left" ,culng(2^31*rnd())
dim as integer fps,frame
var tStart=Timer()
while inkey()=""
Mirror() : flip
Mirror(,false) : flip
Mirror() : flip
Mirror(,false) : flip
frame+=4
if frame mod 300=0 then
var tNow=Timer()
fps = 300/(tNow-tStart) : tStart=tNow
windowtitle "fps: " & fps
end if
' sleep 10
wend