Post by tsh73 on Dec 29, 2020 20:41:59 GMT
Based on RotateBMP
from this thread
justbasiccom.proboards.com/thread/606/rotate-text-graphic-window
Just set path$ to your sprite folder (it needs cave1.bmp, cave2.bmp) and run it
Tested in JB 1.01, JB 2.0
from this thread
justbasiccom.proboards.com/thread/606/rotate-text-graphic-window
Just set path$ to your sprite folder (it needs cave1.bmp, cave2.bmp) and run it
Tested in JB 1.01, JB 2.0
'using rotateBMP to rotate sprite.
'tsh73 Dec 2020
nomainwin
open "test" for graphics_nsb_nf as #gr
#gr "fill cyan; flush"
#gr "trapclose [quit]"
#gr "down"
gr$="#gr"
'insert right path to sprite here
path$="C:\progs\Just BASIC v1.01\SPRITES"
infName$="cave1.bmp"
fullInFName$=path$+"\"+infName$
outfName1$="cave1R.bmp"
call rotateSprite fullInFName$, outfName1$, 0, gr$
infName$="cave2.bmp"
fullInFName$=path$+"\"+infName$
outfName2$="cave2R.bmp"
call rotateSprite fullInFName$, outfName2$, 0, gr$
'now use them
'window client size
#gr$ "cls; home; posxy cx cy"
'sprite size
call GetBmpDimensions fullInFName$, w, h
h=h/2
'h w for rotated
'add all 4 sprites, make them run
infName$="cave1.bmp"
fullInFName$=path$+"\"+infName$
loadbmp "pic1", fullInFName$
infName$="cave2.bmp"
fullInFName$=path$+"\"+infName$
loadbmp "pic2", fullInFName$
loadbmp "pic3", outfName1$
loadbmp "pic4", outfName2$
#gr$ "addsprite horiz pic1 pic2"
#gr$ "cyclesprite horiz 1"
#gr$ "spritexy horiz ";0;" ";2*cy-h
#gr$ "spritemovexy horiz 10 0";
#gr$ "addsprite vert pic3 pic4"
#gr$ "cyclesprite vert 1"
#gr$ "spritevisible vert off";
timer 100, [tick]
'wait
dir = 0 ' -> ^ <- v, 0..3
sprite$="horiz"
[tick]
#gr$ "drawsprites"
#gr$ "spritexy? ";sprite$;" x y"
select case dir
case 0
if x >2*cx-w then
#gr$ "spritevisible ";sprite$;" off"
sprite$="vert"
#gr$ "spriteorient ";sprite$;" normal"
#gr$ "spritevisible ";sprite$;" on"
#gr$ "spritexy ";sprite$;" ";2*cx-h;" ";2*cy-w
#gr$ "spritemovexy ";sprite$;" 0 -10"
dir=(dir+1) mod 4
end if
case 1
if y <0 then
#gr$ "spritevisible ";sprite$;" off"
sprite$="horiz"
#gr$ "spriteorient ";sprite$;" rotate180"
#gr$ "spritevisible ";sprite$;" on"
#gr$ "spritexy ";sprite$;" ";2*cx-w;" ";0
#gr$ "spritemovexy ";sprite$;" -10 0"
dir=(dir+1) mod 4
end if
case 2
if x <0 then
#gr$ "spritevisible ";sprite$;" off"
sprite$="vert"
#gr$ "spriteorient ";sprite$;" rotate180"
#gr$ "spritevisible ";sprite$;" on"
#gr$ "spritexy ";sprite$;" ";0;" ";0
#gr$ "spritemovexy ";sprite$;" 0 10"
dir=(dir+1) mod 4
end if
case 3
if y >2*cy-w then
#gr$ "spritevisible ";sprite$;" off"
sprite$="horiz"
#gr$ "spriteorient ";sprite$;" normal"
#gr$ "spritevisible ";sprite$;" on"
#gr$ "spritexy ";sprite$;" ";0;" ";2*cy-h
#gr$ "spritemovexy ";sprite$;" 10 0"
dir=(dir+1) mod 4
end if
end select
wait
wait
[quit]
timer 0
close #gr
end
sub rotateSprite src$, dest$, isClockwise, gr$
call GetBmpDimensions src$, w, h
loadbmp "src", src$
#gr$ "drawbmp src 0 0"
x0=0:y0=0:ww=w:hh=h/2 'from source
#gr$ "getbmp mask ";x0;" ";y0;" ";ww;" ";hh
bmpsave "mask", "bmp_mask.bmp"
call rotateBMP "bmp_mask.bmp", "bmp_maskR.bmp", isClockwise
x0=0:y0=hh:ww=w:hh=h/2
#gr$ "getbmp pic ";x0;" ";y0;" ";ww;" ";hh
bmpsave "pic", "bmp_pic.bmp"
call rotateBMP "bmp_pic.bmp", "bmp_picR.bmp", isClockwise
#gr$ "cls"
x0=0
loadbmp "maskR", "bmp_maskR.bmp"
#gr$ "drawbmp maskR ";x0;" 0"
loadbmp "picR", "bmp_picR.bmp"
#gr$ "drawbmp picR ";x0;" ";ww
'#gr "color red"
'call rect "#gr", x0,0, hh, ww*2
#gr$ "getbmp sprite1R ";x0;" ";0;" "; hh;" "; ww*2
'#gr "getbmp sprite1R ";fourNum2str$(x0,0, hh, ww*2)
bmpsave "sprite1R", dest$
end sub
'==================================
'Custom functions and subs:
sub GetBmpDimensions fileName$, byref width, byref height
open fileName$ for input as #gbd
temp$ = input$(#gbd, 24)
close #gbd
width = asc(mid$(temp$, 19, 1))+asc(mid$(temp$, 20, 1))*256
height = asc(mid$(temp$, 23, 1))+asc(mid$(temp$, 24, 1))*256
end sub
sub rect gr$, x,y,w,h
#gr$ "place " ;x;" ";y
#gr$ "box ";x+w;" ";y+h
end sub
function fourNum2str$(a,b,c,d)
fourNum2str$="";int(a);" ";int(b);" ";int(c);" ";int(d)
end function
'--------------------------------
sub rotateBMP src$, dest$, isClockwise
open src$ for binary as #fIn
if lof(#fIn)<66 Then
notice "rotateBMP ERROR"+chr$(13)+src$+" too short ("+str$(lof(#fIn))+")"+chr$(13)+"(header should be is 66 bytes)"
close #fIn
exit sub
end if
pre$ =input$( #fIn, 66) ' x42 ie 66 byte preamble
'minimal checks
if left$(pre$, 2)<>"BM" Then
notice "rotateBMP ERROR"+chr$(13)+src$+" doesn't look like BMP"+chr$(13)+"(no BM signature)"
close #fIn
exit sub
end if
if asc(mid$(pre$, 29, 1))<>32 Then
notice "rotateBMP ERROR"+chr$(13)+src$+" doesn't look like 32 bit BMP"+chr$(13)+"(BMPSAVE of JB/LB creates right format)"
close #fIn
exit sub
end if
Width = asc(mid$(pre$, 19, 1))+asc(mid$(pre$, 20, 1))*256
Height = asc(mid$(pre$, 23, 1))+asc(mid$(pre$, 24, 1))*256
dim Pix$( Width, Height) ' set up local pixel arrays Pix$( x, y) holding 'BGR0' as 4 bytes)
'whole data (not used)
'pixel$ =input$( #fIn, 4 *Width *Height)
seek #fIn, 66
for y =0 to Height -1
for x =0 to Width -1
Pix$( x, y) =input$( #fIn, 4) ' x20 =32 ie 4-bytes per pixel
' if x=1 and y=1 then
' c$=Pix$( x, y)
' notice asc(mid$(c$,1,1));" ";asc(mid$(c$,2,1));" ";asc(mid$(c$,3,1));" ";asc(mid$(c$,4,1))
' end if
next x
next y
newPre$ =left$( pre$, 18) +fourByte$( Height) +fourByte$( Width) +mid$( pre$, 27, 51) 'less then 51 - actually up to end
close #fIn
'trunc file first
open dest$ for output as #fOut
close #fOut
open dest$ for binary as #fOut
#fOut, newPre$;
if isClockwise Then
'notice "clockwise"
for x =Width -1 to 0 step -1
for y =0 to Height -1
#fOut, Pix$( x, y);
scan
next y
next x
else
'notice "couter-clockwise"
for x =0 to Width -1
for y =Height -1 to 0 step -1
#fOut, Pix$( x, y);
scan
next y
next x
end if
close #fOut
redim Pix$(1,1) 'attempt to free memory
end sub
function fourByte$( i)
fourByte$ =""
for j = 1 to 4
b = i mod 256
i =(i-b) /256
fourByte$=fourByte$+chr$(b)
next
end function
'==================================