|
Post by tsh73 on Feb 3, 2019 21:59:41 GMT
LB has bitBlt API and stuff, JB can creatively use getbmp/drawbmp. Might as well get handy. ("flip" and "mirror" do what they say, "copy" just getbmp/drawbmp to another place, and "rect" could be used for debugging - to pinpoint exact place we copy from.)
'mirror and flip 'by getbmp line by line 'and ouputting backwards nomainwin open "test" for graphics_nsb_nf as #gr #gr "trapclose [quit]" #gr "down" '#gr "fill white; flush" #gr "home; posxy cx cy"
#gr "home" #gr "backcolor yellow; circlefilled 50"
#gr "backcolor white; circle 20" call rect "#gr", cx, cy, 30, 20, call copy "#gr", cx, cy, 30, 20, 80,100
call mirror "#gr", cx, cy, 30, 20, 200,100 call flip "#gr", cx, cy, 30, 20, 200,200
#gr "flush"
wait
[quit] timer 0 close #gr end
sub rect gr$, x,y,w,h #gr$ "place " ;x;" ";y #gr$ "box ";x+w;" ";y+h end sub
sub copy gr$, x,y,w,h,destX,destY #gr$ "getbmp tmpBmp ";x;" ";y;" ";w;" ";h #gr$ "drawbmp tmpBmp ";destX;" ";destY end sub
sub mirror gr$, x,y,w,h,destX,destY for i=1 to w #gr$ "getbmp tmpBmp ";x+w-i;" ";y;" 1 ";h #gr$ "drawbmp tmpBmp ";destX+i;" ";destY next end sub
sub flip gr$, x,y,w,h,destX,destY for i=1 to h #gr$ "getbmp tmpBmp ";x;" ";y+h-i;" ";w;" 1 " #gr$ "drawbmp tmpBmp ";destX;" ";destY+i next end sub
|
|
|
Post by B+ on Feb 4, 2019 0:08:17 GMT
Nice, thanks!
|
|
|
Post by B+ on Feb 4, 2019 19:39:06 GMT
Let's add Rotations to our bag of tricks! ' Mirror, Flip and Rotation.txt for JB v2 B+ 2019-02-04 ' B+ mod adding to tsh73 tips and utilties: mirror and flip by getbmp line by line and ouputting backwards ' 2019-02-04 B+ adding rotation and demos
global pi, d2r, r2d, XMAX, YMAX
pi = acs(-1) d2r = pi/180 'convert degree angle units to radians r2d = 180/pi 'convert radian angle units to degrees XMAX = 500 '<======================================== actual drawing space needed YMAX = 600 '<======================================== actual drawing space needed
nomainwin WindowWidth = XMAX + 8 WindowHeight = YMAX + 32 UpperLeftX = (DisplayWidth - XMAX) / 2 'or delete if XMAX is 1200 or above UpperLeftY = (DisplayHeight - YMAX) / 2 'or delete if YMAX is 700 or above
open "Mirror, Flip and Rotation" for graphics_nsb_nf as #gr #gr "trapclose quit" #gr "when characterInput charIn" #gr "setfocus" #gr "font arial ";7;" ";16 #gr "down" #gr "home; posxy cx cy"
'draw sample graphic #gr "backcolor yellow; circlefilled 50" #gr "backcolor white; circle 20" call rect "#gr", cx, cy, 30, 20
'draw a copy call copy "#gr", cx, cy, 30, 20, cx + 70 ,cy #gr "place ";cx + 70 + 30 + 10;" ";cy + 15;";|";"Copy"
'draw a mirror call mirror "#gr", cx, cy, 30, 20, cx - 70 - 30, cy #gr "place ";cx - 70 - 30 - 10 - 40;" ";cy + 15;";|";"Mirror"
'draw a flip call flip "#gr", cx, cy, 30, 20, cx - 15, cy - 70 - 20 #gr "place ";cx - 15 + 2;" ";cy - 70 - 25 ;";|";"Flip"
'draw 11 rotations #gr "backcolor white" for i = 1 to 11 scan rada = rada + 2*pi/12 call rotate "#gr", cx, cy, 30, 20, cx - 15, cy + 70, rada #gr "color black" #gr "place ";cx - 35;" ";cy + 70 + 20 + 5 + 20;";|";str$(int(rada * r2d + .01));" degrees" #gr "place ";cx - 25;" ";cy + 70 + 20 + 5 + 40;";|";"Rotation" call pause 1500 if i < 11 then #gr "color white" #gr "place ";cx;" ";cy + 70 + 10 #gr "circlefilled 19" end if next
'now that we can rotate a bmp, try rotating letters 'drawing letters for bmp copies, doing in a column to get clear picture of each letters for l = 1 to 26 #gr "place ";0;" ";20 * l;";|";mid$("ABCDEFGHIJKLMNOPQRSTUVWXYZ", l, 1) next
'testing char cell dimensions by drawing boxes around letters, 'call rect "gr#", 26*8.5, 0, 9, 20 'find cw, ch dang! cw way too inconsistent, so draw the letters in a column instead of a row cw = 12: ch = 20 'character cell width and height
'drawing circle of letters lradius = 180 'letters radius la = 2 * pi/26 'angle between letters for l = 0 to 25 '26 letters ' the letter A is North at letter 0 so add 270 degrees = 3*pi/2 to adjust upright letter at North call rotate "#gr", 0, (l)*20, cw, ch, cx + lradius * cos(la * l + 3*pi/2 ), cy + lradius * sin(la * l + 3*pi/2), la*l next
#gr "flush" wait
sub rect gr$, x,y,w,h #gr$ "place " ;x;" ";y #gr$ "box ";x+w;" ";y+h end sub
sub copy gr$, x,y,w,h,destX,destY #gr$ "getbmp tmpBmp ";x;" ";y;" ";w;" ";h #gr$ "drawbmp tmpBmp ";destX;" ";destY end sub
sub mirror gr$, x,y,w,h,destX,destY for i=1 to w #gr$ "getbmp tmpBmp ";x+w-i;" ";y;" 1 ";h #gr$ "drawbmp tmpBmp ";destX+i;" ";destY next end sub
sub flip gr$, x,y,w,h,destX,destY for i=1 to h #gr$ "getbmp tmpBmp ";x;" ";y+h-i;" ";w;" 1 " #gr$ "drawbmp tmpBmp ";destX;" ";destY+i next end sub
' this uses Atan2, angleAndDistance, globals pi, r2d, d2r sub rotate gr$, x, y, w, h, destX, destY, rotateRadians x0 = x + w/2 : y0 = y + h/2 rx0 = destX + w/2 : ry0 = destY + h/2 for ry = y to y + h for rx = x to x + w call angleAndDistance x0, y0, rx, ry, ra, dist #gr$ "getbmp tmpBmp ";rx;" ";ry;" ";1.5;" 1.5" #gr$ "drawbmp tmpBmp ";rx0 + dist * cos(ra + rotateRadians);" ";ry0 + dist * sin(ra + rotateRadians) next next end sub
'this sub needs Atan2(y, x) Function and r2d gobal constant to convert radians to degrees sub angleAndDistance x1, y1, x2, y2, byref angle, byref distance angle = Atan2(y2 - y1, x2 - x1) distance = sqr((x2 - x1)^2 + (y2 - y1)^2) end sub
' this sub needs global constants pi and d2r for converting degrees to radians Function Atan2(y, x) 'Atan2 is a function which determines the angle between points 'x1, y1 and x2, y2. The angle returned is in radians 'The angle returned is always in the range of '-PI to PI radians (-180 to 180 degrees) '============================================================== 'NOTE the position of Y and X arguments 'This keeps Atan2 function same as other language versions '==============================================================
If x = 0 Then If y < 0 Then Atan2 = -1.5707963267948967 Else Atan2 = 1.5707963267948967 End If Else chk = atn(y/x) If x < 0 Then If y < 0 Then chk = chk - 3.1415926535897932 Else chk = chk + 3.1415926535897932 End If End If Atan2 = chk End If 'thanks Andy Amaya
'normalize angle between 0 and 2*pi 'if Atan2 < 0 then Atan2 = Atan2 + 2 * pi End Function
sub stext x, y, message$ 'note: have to reset fore or back color after ink #gr "place ";x;" ";y;";|";message$ end sub
sub charIn H$, c$ call quit H$ end sub
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
sub quit H$ timer 0 close #H$ end end sub
|
|
|
Post by tsh73 on Feb 4, 2019 21:06:42 GMT
Surprising. Now I wonder if it is faster then with getPixel.
And if picture can be made any smoother by using colors from nearby points.
|
|
|
Post by B+ on Feb 4, 2019 22:01:56 GMT
Alas, we still don't know any color values, just copy paste a pixel at one place to a pixel at another. The coverage is poor except for angles that round well. Still pretty dang clever, for amusement.
A thought: If we could get a list of every point in the destination area, we could back track and find a corresponding point in the source area and send that bmp over to that destination point, then the entire destination area would get covered with something.
|
|
|
Post by tenochtitlanuk on Feb 5, 2019 10:47:49 GMT
|
|
|
Post by Enzo on May 25, 2021 3:13:31 GMT
Can sprites be rotated?
|
|
|
Post by Rod on May 25, 2021 10:07:11 GMT
Yes by 180o, if you want other angles you need to rotate the drawn sprite and capture all angles you need as sprite images. Then load all those images to one sprite and use the spritimage command to show the angle you need at any time. There are one or two rotation drawing examples to search out on this and the Liberty BASIC forum.
|
|
|
Post by tsh73 on May 25, 2021 12:39:54 GMT
|
|
|
Post by Rod on May 25, 2021 15:22:38 GMT
|
|