Post by held12345 on Apr 14, 2023 4:40:45 GMT -5
who can change this program please once that
rotate-sprite without mask are saved as bmp.
rotate-sprite without mask are saved as bmp.
thanks
greeting
nomainwin
WindowWidth=1000
WindowHeight=600
UpperLeftX=(DisplayWidth-WindowWidth)/2
UpperLeftY=(DisplayHeight-WindowHeight)/2
menu #1, "&File", "&Open Sprite",[openSprite],_
"&Save As...",[saveAs],|,"E&xit",[quit]
open "Rotate and Mask Sprite" for graphics_nsb as #1
#1 "down ; trapclose [quit]"
hWindow=hwnd(#1)
CallDll #user32, "GetDC",_
hWindow as ulong,_
hDC as ulong
wait
[quit]
CallDll #user32, "ReleaseDC",_
hWindow as ulong,_
hDC as ulong,_
r as long
close #1
end
[openSprite]
if hBitmap<>0 then
unloadbmp ("bm")
#1 "cls"
end if
filedialog "Open Sprite","*.bmp",bitmap$
if bitmap$="" then wait
loadbmp "bm" , bitmap$
hBitmap=hbmp("bm")
bmpheight=HeightBitmap(bitmap$)
bmpwidth=WidthBitmap(bitmap$)
midx=int(bmpwidth/2)
midy=int(bmpheight/2)+bmpheight
radi=int(bmpwidth/2)
#1 "fill black"
#1 "drawbmp bm 0 ";bmpheight
for angle= 0 to 337.5 step 22.5
newx=newx+bmpwidth
call rotate angle,newx,midx,midy,radi, hWindow, hDC
next
call MakeMask bmpwidth, bmpheight, hWindow, hDC
wait
[saveAs]
#1 "getbmp SpriteMask 0 0 ";bmpwidth;" ";2*bmpheight
filedialog "Save As... ","*.bmp",savefile$
if savefile$="" then wait
newx=0
for a=1 to 26
#1 "getbmp SpriteMask ";newx;" 0 ";bmpwidth;" ";2*bmpheight
bmpsave "SpriteMask",left$(savefile$,len(savefile$)-4)+str$(a)+".bmp"
newx=newx+bmpwidth
next
wait
'************FUNCTIONS******************
function WidthBitmap(name$)
open name$ for input as #pic
pic$=input$(#pic,29)
close #pic
WidthBitmap = asc(mid$(pic$,19,1)) + _
(asc(mid$(pic$,20,1)) * 256)
end function
function HeightBitmap(name$)
open name$ for input as #pic
pic$=input$(#pic,29)
close #pic
HeightBitmap = asc(mid$(pic$,23,1)) + _
(asc(mid$(pic$,24,1)) * 256)
end function
sub rotate angle, newx, midx, midy, radi, hWindow, hDC
for d = 0 to radi
for n= 1 to 360 step .5
scan
x=int(midx-(d*sin(n/57.29577951)))
y=int(midy-(d*cos(n/57.29577951)))
CallDll #gdi32, "GetPixel",_
hDC as ulong,_
x as long,_
y as long,_
pColor as long
a=n+angle mod 360
x=int(midx-(d*sin(a/57.29577951)))
y=int(midy-(d*cos(a/57.29577951)))
x=x+newx
CallDll #gdi32, "SetPixel",_
hDC as ulong,_
x as long,_
y as long,_
pColor as long,_
r as long
next n
next d
end sub
sub MakeMask wide, high, hWnd,hDC
white=(255*256*256)+(255*256)+255
black=0
for x = 0 to 26*wide-1
for y = high to 2*high-1
CallDll #gdi32, "GetPixel",_
hDC as ulong,_
x as long,_
y as long,_
pColor as long
if pColor=black then
newColor=white
else
newColor=black
end if
j=y-high
CallDll #gdi32, "SetPixel",_
hDC as ulong,_
x as long, _
j as long, _
newColor as long, _
r as long
next y
next x
end sub