They both produce the exact same screens.
_Title "Pie Chart 3 Test DisplayImage" ' b+ 2021-11-06 fix up Russian Circle Diagram 'ref https://www.qb64.org/forum/index.php?topic=4367.msg137864#msg137864
'2021-11-07 PieChart 3 Test DisplayImage
' also move one for block out of loop, only need once
'Screen 12
N = 13
d
(i
) = Int(Rnd * 90 + 9) ' min 9, max 99.99.. S = S + d(i)
sumD(i) = S
For i
= 1 To N
' better fill method? ra(i) = sumD(i) * 2 * 3.1416 / S
x
= _Width / 2 + 50 + radius
* Cos(ra
(i
) + offset
) Paint (_Width / 2 + 50 + (radius
- 10) * Cos(ra
(i
) + offset
- _Pi(1 / 36)), _Height / 2 + (radius
- 10) * Sin(ra
(i
) + offset
- _Pi(1 / 36))), i
, &HFFFFFFFF If i
= 1 Then a
= ra
(1) / 2 + offset
Else a
= (ra
(i
) + ra
(i
- 1)) / 2 + offset
wheel&
= _NewImage(2 * radius
+ 2, 2 * radius
+ 2, 12)
_PutImage , 0, wheel&
, (xc
- radius
- 1, yc
- radius
- 1)-(xc
+ radius
+ 1, yc
+ radius
+ 1) 'Cls ' check image capture
'_PutImage , wheel&, 0
'Sleep
' Color i: Print d(i); ra(i)
'Color 15: Print S; "= SUM "
offset
= offset
+ _Pi(1 / 360)
' ==== Testing
' Testing the two subroutines for image rotation, un-comment the one to try and comment out the other
RotoZoom3 xc, yc, wheel&, 1, 1, offset ' very raggedy with bad edge on circle
DisplayImage wheel&, xc, yc, 1, 1, offset, 0
CompareScreens
' ==================================================================================================
' _Display
' Description:
' Started from a mod of Galleon's in Wiki that both scales and rotates an image.
' This version scales the x-axis and y-axis independently allowing rotations of image just by changing X or Y Scales
' making this tightly coded routine a very powerful and versatile image tool.
' This assumes you have set your drawing location with _DEST or default to screen.
' X, Y - is where you want to put the middle of the image
' Image - is the handle assigned with _LOADIMAGE
' xScale, yScale - are shrinkage < 1 or magnification > 1 on the given axis, 1 just uses image size.
' These are multipliers so .5 will create image .5 size on given axis and 2 for twice image size.
' radianRotation is the Angle in Radian units to rotate the image
' note: Radian units for rotation because it matches angle units of other Basic Trig functions
' and saves a little time converting from degree.
' Use the _D2R() function if you prefer to work in degree units for angles.
Dim W&
, H&
, sinr!
, cosr!
, i&
, x2&
, y2&
' variables for image manipulation px(0) = -W& / 2: py(0) = -H& / 2 'left top corner
px(1) = -W& / 2: py(1) = H& / 2 ' left bottom corner
px(2) = W& / 2: py(2) = H& / 2 ' right bottom
px(3) = W& / 2: py(3) = -H& / 2 ' right top
sinr!
= Sin(-radianRotation
): cosr!
= Cos(-radianRotation
) ' rotation helpers For i&
= 0 To 3 ' calc new point locations with rotation and zoom x2& = xScale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = yScale * (py(i&) * cosr! - px(i&) * sinr!) + Y
px(i&) = x2&: py(i&) = y2&
' SMcNeill ref: https://www.qb64.org/forum/index.php?topic=4374.msg137907#msg137907
'Image is the image handle which we use to reference our image.
'x,y is the X/Y coordinates where we want the image to be at on the screen.
'angle is the angle which we wish to rotate the image.
'mode determines HOW we place the image at point X,Y.
'Mode 0 we center the image at point X,Y
'Mode 1 we place the Top Left corner of oour image at point X,Y
'Mode 2 is Bottom Left
'Mode 3 is Top Right
'Mode 4 is Bottom Right
px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2
px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0
px(1) = 0: py(1) = h: px(2) = w: py(2) = h
px(0) = 0: py(0) = -h: px(3) = w: py(3) = -h
px(1) = 0: py(1) = 0: px(2) = w: py(2) = 0
px(0) = -w: py(0) = 0: px(3) = 0: py(3) = 0
px(1) = -w: py(1) = h: px(2) = 0: py(2) = h
px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h
px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
'sinr = Sin(angle / 57.2957795131): cosr = Cos(angle / 57.2957795131)
sinr!
= Sin(-angle
): cosr!
= Cos(-angle
) ' rotation helpers x2 = xscale * (px(i) * cosr + sinr * py(i)) + x: y2 = yscale * (py(i) * cosr - px(i) * sinr) + y
px(i) = x2: py(i) = y2
_MapTriangle (0, 0)-(0, h
- 1)-(w
- 1, h
- 1), Image
To(px
(0), py
(0))-(px
(1), py
(1))-(px
(2), py
(2)) _MapTriangle (0, 0)-(w
- 1, 0)-(w
- 1, h
- 1), Image
To(px
(0), py
(0))-(px
(3), py
(3))-(px
(2), py
(2))
As for the angle, that's just my personal preference at work, and it goes in the direction which one would draw on a piece of graph paper. 45 degrees is sloping from (0,0) up to (1,1) and beyond, not from (0,0) to (1,-1). Your RotoZoom3 even reverses the angles for you automatically: sinr! = Sin(-radianRotation): cosr! = Cos(-radianRotation).
Once I swapped from degree to reverse radian with DisplayScreen, everything works the same as yours, though it's slow as crap and requires you to hold down the spacebar or something to watch as it slowly rotates and compares every pixel from one screen against every pixel on the second screen for a discrepancy..
The only difference I made was this one in the SUB:
FROM -- sinr = Sin(angle / 57.2957795131): cosr = Cos(angle / 57.2957795131)
TO -- sinr! = Sin(-angle): cosr! = Cos(-angle) ' rotation helpers
(along with the change to call without having to use _R2D for the angle)
If there's something raggedy at work, it's the same for both RotoZoom3 and DisplayImage. Afterall, back when I did DisplayImage ages ago, I based it off RotoZoom at the time so that it'd be able to work as I needed it to for a program which was drawing boxes on the screen. (I think it was a calendar type program...) Each box needed to be positioned starting AT point (x,y) and not CENTERED at point (x,y), which is why I added the mode option. And, as usual, I just figured, "If I'm going to sort it out for one corner, why not sort it out for all of them?"
Take the mode adjustment out and you basically have your RotoZoom3 line for line, I think. (Except for mine is set for degrees by default rather than radians, and the angle isn't reversed as you have yours.)
If you draw a circle on paper, angles go counter-clockwise naturally. 45 degrees is in the first quadrant while 315 degrees is in the 4th quadrant. You've made yours backwards just to have clockwise rotation. :P
And something completely unrelated, but odd with the test code above:
If you take out all those SLEEP statements, the program goes 100% buggy weird, like so:
_Title "Pie Chart 3 Test DisplayImage" ' b+ 2021-11-06 fix up Russian Circle Diagram 'ref https://www.qb64.org/forum/index.php?topic=4367.msg137864#msg137864
'2021-11-07 PieChart 3 Test DisplayImage
' also move one for block out of loop, only need once
'Screen 12
N = 13
d
(i
) = Int(Rnd * 90 + 9) ' min 9, max 99.99.. S = S + d(i)
sumD(i) = S
For i
= 1 To N
' better fill method? ra(i) = sumD(i) * 2 * 3.1416 / S
x
= _Width / 2 + 50 + radius
* Cos(ra
(i
) + offset
) Paint (_Width / 2 + 50 + (radius
- 10) * Cos(ra
(i
) + offset
- _Pi(1 / 36)), _Height / 2 + (radius
- 10) * Sin(ra
(i
) + offset
- _Pi(1 / 36))), i
, &HFFFFFFFF If i
= 1 Then a
= ra
(1) / 2 + offset
Else a
= (ra
(i
) + ra
(i
- 1)) / 2 + offset
wheel&
= _NewImage(2 * radius
+ 2, 2 * radius
+ 2, 12)
_PutImage , 0, wheel&
, (xc
- radius
- 1, yc
- radius
- 1)-(xc
+ radius
+ 1, yc
+ radius
+ 1) 'Cls ' check image capture
'_PutImage , wheel&, 0
'Sleep
' Color i: Print d(i); ra(i)
'Color 15: Print S; "= SUM "
offset
= offset
+ _Pi(1 / 360)
' ==== Testing
' Testing the two subroutines for image rotation, un-comment the one to try and comment out the other
RotoZoom3 xc, yc, wheel&, 1, 1, offset ' very raggedy with bad edge on circle
'Sleep
DisplayImage wheel&, xc, yc, 1, 1, offset, 0
'Sleep
'CompareScreens
' ==================================================================================================
' _Display
' Description:
' Started from a mod of Galleon's in Wiki that both scales and rotates an image.
' This version scales the x-axis and y-axis independently allowing rotations of image just by changing X or Y Scales
' making this tightly coded routine a very powerful and versatile image tool.
' This assumes you have set your drawing location with _DEST or default to screen.
' X, Y - is where you want to put the middle of the image
' Image - is the handle assigned with _LOADIMAGE
' xScale, yScale - are shrinkage < 1 or magnification > 1 on the given axis, 1 just uses image size.
' These are multipliers so .5 will create image .5 size on given axis and 2 for twice image size.
' radianRotation is the Angle in Radian units to rotate the image
' note: Radian units for rotation because it matches angle units of other Basic Trig functions
' and saves a little time converting from degree.
' Use the _D2R() function if you prefer to work in degree units for angles.
Dim W&
, H&
, sinr!
, cosr!
, i&
, x2&
, y2&
' variables for image manipulation px(0) = -W& / 2: py(0) = -H& / 2 'left top corner
px(1) = -W& / 2: py(1) = H& / 2 ' left bottom corner
px(2) = W& / 2: py(2) = H& / 2 ' right bottom
px(3) = W& / 2: py(3) = -H& / 2 ' right top
sinr!
= Sin(-radianRotation
): cosr!
= Cos(-radianRotation
) ' rotation helpers For i&
= 0 To 3 ' calc new point locations with rotation and zoom x2& = xScale * (px(i&) * cosr! + sinr! * py(i&)) + X: y2& = yScale * (py(i&) * cosr! - px(i&) * sinr!) + Y
px(i&) = x2&: py(i&) = y2&
' SMcNeill ref: https://www.qb64.org/forum/index.php?topic=4374.msg137907#msg137907
'Image is the image handle which we use to reference our image.
'x,y is the X/Y coordinates where we want the image to be at on the screen.
'angle is the angle which we wish to rotate the image.
'mode determines HOW we place the image at point X,Y.
'Mode 0 we center the image at point X,Y
'Mode 1 we place the Top Left corner of oour image at point X,Y
'Mode 2 is Bottom Left
'Mode 3 is Top Right
'Mode 4 is Bottom Right
px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2
px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0
px(1) = 0: py(1) = h: px(2) = w: py(2) = h
px(0) = 0: py(0) = -h: px(3) = w: py(3) = -h
px(1) = 0: py(1) = 0: px(2) = w: py(2) = 0
px(0) = -w: py(0) = 0: px(3) = 0: py(3) = 0
px(1) = -w: py(1) = h: px(2) = 0: py(2) = h
px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h
px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
'sinr = Sin(angle / 57.2957795131): cosr = Cos(angle / 57.2957795131)
sinr!
= Sin(-angle
): cosr!
= Cos(-angle
) ' rotation helpers x2 = xscale * (px(i) * cosr + sinr * py(i)) + x: y2 = yscale * (py(i) * cosr - px(i) * sinr) + y
px(i) = x2: py(i) = y2
_MapTriangle (0, 0)-(0, h
- 1)-(w
- 1, h
- 1), Image
To(px
(0), py
(0))-(px
(1), py
(1))-(px
(2), py
(2)) _MapTriangle (0, 0)-(w
- 1, 0)-(w
- 1, h
- 1), Image
To(px
(0), py
(0))-(px
(3), py
(3))-(px
(2), py
(2))
Apparently, GL doesn't like the constant switching from SCREEN FirstScreen to SCREEN SecondScreen
WARNING: If you decide to test the second code, for the love of your PC, know how to open your Task Manager and end a process. I've tested it several times and lets just say the results end up getting completely unreliable with us. The red X in the top right *might* end and close the program. It might not... Alt-F4 may work... ESC might stop it... Then again, it may not...
The constant swap from one SCREEN to another 30 times per second ends up doing something to the video memory with GL. Honestly, I'd suggest being prepared to do a system reboot once you're finished playing around with it and watching it die horribly.
Even more oddly, if you REPLACE those two SLEEP statements with _DISPLAY and make the screen manually update, the program works just fine. It's just wuth _AUTODISPLAY at work that GL doesn't like the swapping of screen modes constantly.
Who knew?!!