Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
07-03-2023, 01:40 AM
(This post was last modified: 07-03-2023, 01:42 AM by mnrvovrfc.)
(07-03-2023, 12:35 AM)PhilOfPerth Wrote: When I run your code I get a perfect ellipse. But I was looking to change the angle (the two axes of the ellipse). I'm experimenting with ang at the moment.
No luck so far.
Try employing two variables for "ang", one for X-axis and the other for Y-axis. Make them different from each other.
Hmm the two "semi" variables should have been enough because the one for X-axis is much larger in this example. But it's because most of today's screens are much wider than they are tall. Tricks are required to make a circle look like a circle on these screens. It wasn't different while we had to use televisions and those heavy rounded glass things that projected moving light...
Posts: 276
Threads: 14
Joined: Apr 2022
Reputation:
27
If I understand correctly, is this the sort of thing you're looking for? It now subjects each point to a transformation matrix operation. That's somewhat more trig work than before. Now it creates the plot (x, y) relative to a (0, 0) origin, performs the rotation (in radians), and THEN centers it in the screen after it's properly plotted and rotated. If you prefer degrees then just; rotate! = _D2R(degrees)
Code: (Select All) 'de La Hire's method of ellipse
'geometric construction of two concentric circles
'the outermost diameter equals the desired ellipse's
'semi major axis, while the inner circle matches the
'semi minor axis.
'a full 360ø rotation is executed and the positions
'are plotted using a COS function of the outer circle's
'resulting X position and SIN function of the inner
'circle's Y position.
SCREEN _NEWIMAGE(1024, 512, 32)
cen_x% = 512 ' screen center x
cen_y% = 256 ' screen center y
semi_maj% = 200 ' Semi major axis of ellipse i.e. outer circle
semi_min% = 105 ' Semi minor axis of ellipse i.e. inner circle
rotate! = .75 ' radian rotation of ellipse
cursx% = semi_maj% * COS(rotate!)
cursy% = semi_maj% * SIN(rotate!)
PSET (cursx% + cen_x%, cursy% + cen_y%) ' pre-position graphics cursor
FOR ang = 0 TO 2 * _PI STEP .01 ' granularity of 1/100 radian
x% = semi_maj% * COS(ang) ' x position a COS function of the outer circle
y% = semi_min% * SIN(ang) ' y position a SIN function of the inner circle
xr% = x% * COS(rotate!) - y% * SIN(rotate!) + cen_x%
yr% = x% * SIN(rotate!) + y% * COS(rotate!) + cen_y%
LINE STEP(0, 0)-(xr%, yr%) ' line from previous cursor position
NEXT ang
DO: LOOP: DO: LOOP
sha_na_na_na_na_na_na_na_na_na:
Posts: 651
Threads: 96
Joined: Apr 2022
Reputation:
22
07-03-2023, 06:12 AM
(This post was last modified: 07-03-2023, 06:54 AM by PhilOfPerth.)
(07-03-2023, 03:52 AM)OldMoses Wrote: If I understand correctly, is this the sort of thing you're looking for? It now subjects each point to a transformation matrix operation. That's somewhat more trig work than before. Now it creates the plot (x, y) relative to a (0, 0) origin, performs the rotation (in radians), and THEN centers it in the screen after it's properly plotted and rotated. If you prefer degrees then just; rotate! = _D2R(degrees)
Code: (Select All) 'de La Hire's method of ellipse
'geometric construction of two concentric circles
'the outermost diameter equals the desired ellipse's
'semi major axis, while the inner circle matches the
'semi minor axis.
'a full 360ø rotation is executed and the positions
'are plotted using a COS function of the outer circle's
'resulting X position and SIN function of the inner
'circle's Y position.
SCREEN _NEWIMAGE(1024, 512, 32)
cen_x% = 512 ' screen center x
cen_y% = 256 ' screen center y
semi_maj% = 200 ' Semi major axis of ellipse i.e. outer circle
semi_min% = 105 ' Semi minor axis of ellipse i.e. inner circle
rotate! = .75 ' radian rotation of ellipse
cursx% = semi_maj% * COS(rotate!)
cursy% = semi_maj% * SIN(rotate!)
PSET (cursx% + cen_x%, cursy% + cen_y%) ' pre-position graphics cursor
FOR ang = 0 TO 2 * _PI STEP .01 ' granularity of 1/100 radian
x% = semi_maj% * COS(ang) ' x position a COS function of the outer circle
y% = semi_min% * SIN(ang) ' y position a SIN function of the inner circle
xr% = x% * COS(rotate!) - y% * SIN(rotate!) + cen_x%
yr% = x% * SIN(rotate!) + y% * COS(rotate!) + cen_y%
LINE STEP(0, 0)-(xr%, yr%) ' line from previous cursor position
NEXT ang
Beautiful! Thank you; I was able to rotate by adding a couple of lines, giving this:
(the color lines make it blink occasionally, I don't know why yet).
Code: (Select All) Screen _NewImage(1024, 512, 32)
cen_x% = 512 ' screen center x
cen_y% = 256 ' screen center y
semi_maj% = 200 ' Semi major axis of ellipse i.e. outer circle
semi_min% = 105 ' Semi minor axis of ellipse i.e. inner circle
Do
For rotate = 0 To 2* _pi Step .1 ' radian rotation of ellipse now increases from 0 to 6
Cls
cursx% = semi_maj% * Cos(rotate!)
cursy% = semi_maj% * Sin(rotate!)
PSet (cursx% + cen_x%, cursy% + cen_y%) ' pre-position graphics cursor
For ang = 0 To 2 * _Pi Step .01 ' granularity of 1/100 radian
x% = semi_maj% * Cos(ang) ' x position a COS function of the outer circle
y% = semi_min% * Sin(ang) ' y position a SIN function of the inner circle
xr% = x% * Cos(rotate!) - y% * Sin(rotate!) + cen_x%
yr% = x% * Sin(rotate!) + y% * Cos(rotate!) + cen_y%
Line Step(0, 0)-(xr%, yr%) ' line from previous cursor position
Next ang
Color _RGB(255, 0, 255)
Paint (512, 256)
_Delay .1 ' allows view of each iteration
Next rotate
Loop
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
07-03-2023, 06:16 AM
(This post was last modified: 07-03-2023, 06:18 AM by SMcNeill.)
Code: (Select All)
Screen _NewImage(800, 600, 32)
Dim TransRed As _Unsigned Long
Dim TransGreen As _Unsigned Long
Dim TransBlue As _Unsigned Long
TransRed = _RGBA(255, 0, 0, 128)
TransGreen = _RGBA(0, 255, 0, 128)
TransBlue = _RGBA(0, 0, 255, 128)
Call CircleFill(100, 100, 75, TransRed)
Call CircleFill(120, 120, 75, TransBlue)
Call EllipseFill(550, 100, 150, 75, TransBlue)
Call EllipseFill(570, 120, 150, 75, TransGreen)
Call EllipseTilt(200, 400, 150, 75, 0, TransGreen)
Call EllipseTilt(220, 420, 150, 75, 3.14 / 4, TransRed)
Call EllipseTiltFill(0, 550, 400, 150, 75, 3.14 / 6, TransRed)
Call EllipseTiltFill(0, 570, 420, 150, 75, 3.14 / 4, TransGreen)
End
Sub CircleFill (CX As Integer, CY As Integer, R As Integer, C As _Unsigned Long)
' CX = center x coordinate
' CY = center y coordinate
' R = radius
' C = fill color
Dim Radius As Integer, RadiusError As Integer
Dim X As Integer, Y As Integer
Radius = Abs(R)
RadiusError = -Radius
X = Radius
Y = 0
If Radius = 0 Then PSet (CX, CY), C: Exit Sub
Line (CX - X, CY)-(CX + X, CY), C, BF
While X > Y
RadiusError = RadiusError + Y * 2 + 1
If RadiusError >= 0 Then
If X <> Y + 1 Then
Line (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
Line (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
End If
X = X - 1
RadiusError = RadiusError - X * 2
End If
Y = Y + 1
Line (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
Line (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
Wend
End Sub
Sub EllipseFill (CX As Integer, CY As Integer, a As Integer, b As Integer, C As _Unsigned Long)
' CX = center x coordinate
' CY = center y coordinate
' a = semimajor axis
' b = semiminor axis
' C = fill color
If a = 0 Or b = 0 Then Exit Sub
Dim h2 As _Integer64
Dim w2 As _Integer64
Dim h2w2 As _Integer64
Dim x As Integer
Dim y As Integer
w2 = a * a
h2 = b * b
h2w2 = h2 * w2
Line (CX - a, CY)-(CX + a, CY), C, BF
Do While y < b
y = y + 1
x = Sqr((h2w2 - y * y * w2) \ h2)
Line (CX - x, CY + y)-(CX + x, CY + y), C, BF
Line (CX - x, CY - y)-(CX + x, CY - y), C, BF
Loop
End Sub
Sub EllipseTilt (CX, CY, a, b, ang, C As _Unsigned Long)
' CX = center x coordinate
' CY = center y coordinate
' a = semimajor axis
' b = semiminor axis
' ang = clockwise orientation of semimajor axis in radians (0 default)
' C = fill color
For k = 0 To 6.283185307179586 + .025 Step .025
i = a * Cos(k) * Cos(ang) + b * Sin(k) * Sin(ang)
j = -a * Cos(k) * Sin(ang) + b * Sin(k) * Cos(ang)
i = i + CX
j = -j + CY
If k <> 0 Then
Line -(i, j), C
Else
PSet (i, j), C
End If
Next
End Sub
Sub EllipseTiltFill (destHandle&, CX, CY, a, b, ang, C As _Unsigned Long)
' destHandle& = destination handle
' CX = center x coordinate
' CY = center y coordinate
' a = semimajor axis
' b = semiminor axis
' ang = clockwise orientation of semimajor axis in radians (0 default)
' C = fill color
Dim max As Integer, mx2 As Integer, i As Integer, j As Integer
Dim prc As _Unsigned Long
Dim D As Integer, S As Integer
D = _Dest: S = _Source
prc = _RGB32(255, 255, 255, 255)
If a > b Then max = a + 1 Else max = b + 1
mx2 = max + max
tef& = _NewImage(mx2, mx2)
_Dest tef&
_Source tef&
For k = 0 To 6.283185307179586 + .025 Step .025
i = max + a * Cos(k) * Cos(ang) + b * Sin(k) * Sin(ang)
j = max + a * Cos(k) * Sin(ang) - b * Sin(k) * Cos(ang)
If k <> 0 Then
Line (lasti, lastj)-(i, j), prc
Else
PSet (i, j), prc
End If
lasti = i: lastj = j
Next
Dim xleft(mx2) As Integer, xright(mx2) As Integer, x As Integer, y As Integer
For y = 0 To mx2
x = 0
While Point(x, y) <> prc And x < mx2
x = x + 1
Wend
xleft(y) = x
While Point(x, y) = prc And x < mx2
x = x + 1
Wend
While Point(x, y) <> prc And x < mx2
x = x + 1
Wend
If x = mx2 Then xright(y) = xleft(y) Else xright(y) = x
Next
_Dest destHandle&
For y = 0 To mx2
If xleft(y) <> mx2 Then Line (xleft(y) + CX - max, y + CY - max)-(xright(y) + CX - max, y + CY - max), C, BF
Next
_Dest D: _Dest S
_FreeImage tef&
End Sub
Those are the routines we worked up ages ago for Circles and Ellipses. They should handle whatever you need for them too, and they've been optimized for speed with QB64PE.
Posts: 651
Threads: 96
Joined: Apr 2022
Reputation:
22
(07-03-2023, 06:16 AM)SMcNeill Wrote: Code: (Select All)
{{CodeStart}}
{{Cl|Screen}} {{Cl|_NewImage}}({{Text|800|#F580B1}}, {{Text|600|#F580B1}}, {{Text|32|#F580B1}})
{{Cl|Dim}} TransRed {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
{{Cl|Dim}} TransGreen {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
{{Cl|Dim}} TransBlue {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
TransRed = {{Cl|_RGBA}}({{Text|255|#F580B1}}, {{Text|0|#F580B1}}, {{Text|0|#F580B1}}, {{Text|128|#F580B1}})
TransGreen = {{Cl|_RGBA}}({{Text|0|#F580B1}}, {{Text|255|#F580B1}}, {{Text|0|#F580B1}}, {{Text|128|#F580B1}})
TransBlue = {{Cl|_RGBA}}({{Text|0|#F580B1}}, {{Text|0|#F580B1}}, {{Text|255|#F580B1}}, {{Text|128|#F580B1}})
{{Cl|Call}} {{Text|CircleFill|#55FF55}}({{Text|100|#F580B1}}, {{Text|100|#F580B1}}, {{Text|75|#F580B1}}, TransRed)
{{Cl|Call}} {{Text|CircleFill|#55FF55}}({{Text|120|#F580B1}}, {{Text|120|#F580B1}}, {{Text|75|#F580B1}}, TransBlue)
{{Cl|Call}} {{Text|EllipseFill|#55FF55}}({{Text|550|#F580B1}}, {{Text|100|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, TransBlue)
{{Cl|Call}} {{Text|EllipseFill|#55FF55}}({{Text|570|#F580B1}}, {{Text|120|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, TransGreen)
{{Cl|Call}} {{Text|EllipseTilt|#55FF55}}({{Text|200|#F580B1}}, {{Text|400|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|0|#F580B1}}, TransGreen)
{{Cl|Call}} {{Text|EllipseTilt|#55FF55}}({{Text|220|#F580B1}}, {{Text|420|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|3.14|#F580B1}} / {{Text|4|#F580B1}}, TransRed)
{{Cl|Call}} {{Text|EllipseTiltFill|#55FF55}}({{Text|0|#F580B1}}, {{Text|550|#F580B1}}, {{Text|400|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|3.14|#F580B1}} / {{Text|6|#F580B1}}, TransRed)
{{Cl|Call}} {{Text|EllipseTiltFill|#55FF55}}({{Text|0|#F580B1}}, {{Text|570|#F580B1}}, {{Text|420|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|3.14|#F580B1}} / {{Text|4|#F580B1}}, TransGreen)
{{Cl|End}}
{{Cl|Sub}} {{Text|CircleFill|#55FF55}} (CX {{Cl|As}} {{Cl|Integer}}, CY {{Cl|As}} {{Cl|Integer}}, R {{Cl|As}} {{Cl|Integer}}, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' R = radius</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|Dim}} Radius {{Cl|As}} {{Cl|Integer}}, RadiusError {{Cl|As}} {{Cl|Integer}}
{{Cl|Dim}} X {{Cl|As}} {{Cl|Integer}}, Y {{Cl|As}} {{Cl|Integer}}
Radius = {{Cl|Abs}}(R)
RadiusError = -Radius
X = Radius
Y = {{Text|0|#F580B1}}
{{Cl|If}} Radius = {{Text|0|#F580B1}} {{Cl|Then}} {{Cl|PSet}} (CX, CY), C: {{Cl|Exit Sub}}
{{Cl|Line}} (CX - X, CY)-(CX + X, CY), C, BF
{{Cl|While}} X > Y
RadiusError = RadiusError + Y * {{Text|2|#F580B1}} + {{Text|1|#F580B1}}
{{Cl|If}} RadiusError >= {{Text|0|#F580B1}} {{Cl|Then}}
{{Cl|If}} X <> Y + {{Text|1|#F580B1}} {{Cl|Then}}
{{Cl|Line}} (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
{{Cl|Line}} (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
{{Cl|End If}}
X = X - {{Text|1|#F580B1}}
RadiusError = RadiusError - X * {{Text|2|#F580B1}}
{{Cl|End If}}
Y = Y + {{Text|1|#F580B1}}
{{Cl|Line}} (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
{{Cl|Line}} (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
{{Cl|Wend}}
{{Cl|End Sub}}
{{Cl|Sub}} {{Text|EllipseFill|#55FF55}} (CX {{Cl|As}} {{Cl|Integer}}, CY {{Cl|As}} {{Cl|Integer}}, a {{Cl|As}} {{Cl|Integer}}, b {{Cl|As}} {{Cl|Integer}}, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' a = semimajor axis</nowiki>|#919191}}
{{Text|<nowiki>' b = semiminor axis</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|If}} a = {{Text|0|#F580B1}} {{Cl|OR (boolean)|Or}} b = {{Text|0|#F580B1}} {{Cl|Then}} {{Cl|Exit Sub}}
{{Cl|Dim}} h2 {{Cl|As}} {{Cl|_Integer64}}
{{Cl|Dim}} w2 {{Cl|As}} {{Cl|_Integer64}}
{{Cl|Dim}} h2w2 {{Cl|As}} {{Cl|_Integer64}}
{{Cl|Dim}} x {{Cl|As}} {{Cl|Integer}}
{{Cl|Dim}} y {{Cl|As}} {{Cl|Integer}}
w2 = a * a
h2 = b * b
h2w2 = h2 * w2
{{Cl|Line}} (CX - a, CY)-(CX + a, CY), C, BF
{{Cl|DO...LOOP|Do While}} y < b
y = y + {{Text|1|#F580B1}}
x = {{Cl|Sqr}}((h2w2 - y * y * w2) \ h2)
{{Cl|Line}} (CX - x, CY + y)-(CX + x, CY + y), C, BF
{{Cl|Line}} (CX - x, CY - y)-(CX + x, CY - y), C, BF
{{Cl|Loop}}
{{Cl|End Sub}}
{{Cl|Sub}} {{Text|EllipseTilt|#55FF55}} (CX, CY, a, b, ang, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' a = semimajor axis</nowiki>|#919191}}
{{Text|<nowiki>' b = semiminor axis</nowiki>|#919191}}
{{Text|<nowiki>' ang = clockwise orientation of semimajor axis in radians (0 default)</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|For}} k = {{Text|0|#F580B1}} {{Cl|To}} {{Text|6.283185307179586|#F580B1}} + {{Text|.025|#F580B1}} {{Cl|Step}} {{Text|.025|#F580B1}}
i = a * {{Cl|Cos}}(k) * {{Cl|Cos}}(ang) + b * {{Cl|Sin}}(k) * {{Cl|Sin}}(ang)
j = -a * {{Cl|Cos}}(k) * {{Cl|Sin}}(ang) + b * {{Cl|Sin}}(k) * {{Cl|Cos}}(ang)
i = i + CX
j = -j + CY
{{Cl|If}} k <> {{Text|0|#F580B1}} {{Cl|Then}}
{{Cl|Line}} -(i, j), C
{{Cl|Else}}
{{Cl|PSet}} (i, j), C
{{Cl|End If}}
{{Cl|Next}}
{{Cl|End Sub}}
{{Cl|Sub}} {{Text|EllipseTiltFill|#55FF55}} (destHandle&, CX, CY, a, b, ang, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' destHandle& = destination handle</nowiki>|#919191}}
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' a = semimajor axis</nowiki>|#919191}}
{{Text|<nowiki>' b = semiminor axis</nowiki>|#919191}}
{{Text|<nowiki>' ang = clockwise orientation of semimajor axis in radians (0 default)</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|Dim}} max {{Cl|As}} {{Cl|Integer}}, mx2 {{Cl|As}} {{Cl|Integer}}, i {{Cl|As}} {{Cl|Integer}}, j {{Cl|As}} {{Cl|Integer}}
{{Cl|Dim}} prc {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
{{Cl|Dim}} D {{Cl|As}} {{Cl|Integer}}, S {{Cl|As}} {{Cl|Integer}}
D = {{Cl|_DEST (function)|_Dest}}: S = {{Cl|_SOURCE (function)|_Source}}
prc = {{Cl|_RGB32}}({{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|255|#F580B1}})
{{Cl|If}} a > b {{Cl|Then}} max = a + {{Text|1|#F580B1}} {{Cl|Else}} max = b + {{Text|1|#F580B1}}
mx2 = max + max
tef& = {{Cl|_NewImage}}(mx2, mx2)
{{Cl|_Dest}} tef&
{{Cl|_Source}} tef&
{{Cl|For}} k = {{Text|0|#F580B1}} {{Cl|To}} {{Text|6.283185307179586|#F580B1}} + {{Text|.025|#F580B1}} {{Cl|Step}} {{Text|.025|#F580B1}}
i = max + a * {{Cl|Cos}}(k) * {{Cl|Cos}}(ang) + b * {{Cl|Sin}}(k) * {{Cl|Sin}}(ang)
j = max + a * {{Cl|Cos}}(k) * {{Cl|Sin}}(ang) - b * {{Cl|Sin}}(k) * {{Cl|Cos}}(ang)
{{Cl|If}} k <> {{Text|0|#F580B1}} {{Cl|Then}}
{{Cl|Line}} (lasti, lastj)-(i, j), prc
{{Cl|Else}}
{{Cl|PSet}} (i, j), prc
{{Cl|End If}}
lasti = i: lastj = j
{{Cl|Next}}
{{Cl|Dim}} xleft(mx2) {{Cl|As}} {{Cl|Integer}}, xright(mx2) {{Cl|As}} {{Cl|Integer}}, x {{Cl|As}} {{Cl|Integer}}, y {{Cl|As}} {{Cl|Integer}}
{{Cl|For}} y = {{Text|0|#F580B1}} {{Cl|To}} mx2
x = {{Text|0|#F580B1}}
{{Cl|While}} {{Cl|Point}}(x, y) <> prc {{Cl|AND (boolean)|And}} x < mx2
x = x + {{Text|1|#F580B1}}
{{Cl|Wend}}
xleft(y) = x
{{Cl|While}} {{Cl|Point}}(x, y) = prc {{Cl|AND (boolean)|And}} x < mx2
x = x + {{Text|1|#F580B1}}
{{Cl|Wend}}
{{Cl|While}} {{Cl|Point}}(x, y) <> prc {{Cl|AND (boolean)|And}} x < mx2
x = x + {{Text|1|#F580B1}}
{{Cl|Wend}}
{{Cl|If}} x = mx2 {{Cl|Then}} xright(y) = xleft(y) {{Cl|Else}} xright(y) = x
{{Cl|Next}}
{{Cl|_Dest}} destHandle&
{{Cl|For}} y = {{Text|0|#F580B1}} {{Cl|To}} mx2
{{Cl|If}} xleft(y) <> mx2 {{Cl|Then}} {{Cl|Line}} (xleft(y) + CX - max, y + CY - max)-(xright(y) + CX - max, y + CY - max), C, BF
{{Cl|Next}}
{{Cl|_Dest}} D: {{Cl|_Dest}} S
{{Cl|_FreeImage}} tef&
{{Cl|End Sub}}
{{CodeEnd}}
Those are the routines we worked up ages ago for Circles and Ellipses. They should handle whatever you need for them too, and they've been optimized for speed with QB64PE.
Thank you Steve. But OldMoses has given me what I needed (see previous post)
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
(07-03-2023, 06:19 AM)PhilOfPerth Wrote: (07-03-2023, 06:16 AM)SMcNeill Wrote: Code: (Select All)
{{CodeStart}}
{{Cl|Screen}} {{Cl|_NewImage}}({{Text|800|#F580B1}}, {{Text|600|#F580B1}}, {{Text|32|#F580B1}})
{{Cl|Dim}} TransRed {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
{{Cl|Dim}} TransGreen {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
{{Cl|Dim}} TransBlue {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
TransRed = {{Cl|_RGBA}}({{Text|255|#F580B1}}, {{Text|0|#F580B1}}, {{Text|0|#F580B1}}, {{Text|128|#F580B1}})
TransGreen = {{Cl|_RGBA}}({{Text|0|#F580B1}}, {{Text|255|#F580B1}}, {{Text|0|#F580B1}}, {{Text|128|#F580B1}})
TransBlue = {{Cl|_RGBA}}({{Text|0|#F580B1}}, {{Text|0|#F580B1}}, {{Text|255|#F580B1}}, {{Text|128|#F580B1}})
{{Cl|Call}} {{Text|CircleFill|#55FF55}}({{Text|100|#F580B1}}, {{Text|100|#F580B1}}, {{Text|75|#F580B1}}, TransRed)
{{Cl|Call}} {{Text|CircleFill|#55FF55}}({{Text|120|#F580B1}}, {{Text|120|#F580B1}}, {{Text|75|#F580B1}}, TransBlue)
{{Cl|Call}} {{Text|EllipseFill|#55FF55}}({{Text|550|#F580B1}}, {{Text|100|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, TransBlue)
{{Cl|Call}} {{Text|EllipseFill|#55FF55}}({{Text|570|#F580B1}}, {{Text|120|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, TransGreen)
{{Cl|Call}} {{Text|EllipseTilt|#55FF55}}({{Text|200|#F580B1}}, {{Text|400|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|0|#F580B1}}, TransGreen)
{{Cl|Call}} {{Text|EllipseTilt|#55FF55}}({{Text|220|#F580B1}}, {{Text|420|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|3.14|#F580B1}} / {{Text|4|#F580B1}}, TransRed)
{{Cl|Call}} {{Text|EllipseTiltFill|#55FF55}}({{Text|0|#F580B1}}, {{Text|550|#F580B1}}, {{Text|400|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|3.14|#F580B1}} / {{Text|6|#F580B1}}, TransRed)
{{Cl|Call}} {{Text|EllipseTiltFill|#55FF55}}({{Text|0|#F580B1}}, {{Text|570|#F580B1}}, {{Text|420|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|3.14|#F580B1}} / {{Text|4|#F580B1}}, TransGreen)
{{Cl|End}}
{{Cl|Sub}} {{Text|CircleFill|#55FF55}} (CX {{Cl|As}} {{Cl|Integer}}, CY {{Cl|As}} {{Cl|Integer}}, R {{Cl|As}} {{Cl|Integer}}, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' R = radius</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|Dim}} Radius {{Cl|As}} {{Cl|Integer}}, RadiusError {{Cl|As}} {{Cl|Integer}}
{{Cl|Dim}} X {{Cl|As}} {{Cl|Integer}}, Y {{Cl|As}} {{Cl|Integer}}
Radius = {{Cl|Abs}}(R)
RadiusError = -Radius
X = Radius
Y = {{Text|0|#F580B1}}
{{Cl|If}} Radius = {{Text|0|#F580B1}} {{Cl|Then}} {{Cl|PSet}} (CX, CY), C: {{Cl|Exit Sub}}
{{Cl|Line}} (CX - X, CY)-(CX + X, CY), C, BF
{{Cl|While}} X > Y
RadiusError = RadiusError + Y * {{Text|2|#F580B1}} + {{Text|1|#F580B1}}
{{Cl|If}} RadiusError >= {{Text|0|#F580B1}} {{Cl|Then}}
{{Cl|If}} X <> Y + {{Text|1|#F580B1}} {{Cl|Then}}
{{Cl|Line}} (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
{{Cl|Line}} (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
{{Cl|End If}}
X = X - {{Text|1|#F580B1}}
RadiusError = RadiusError - X * {{Text|2|#F580B1}}
{{Cl|End If}}
Y = Y + {{Text|1|#F580B1}}
{{Cl|Line}} (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
{{Cl|Line}} (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
{{Cl|Wend}}
{{Cl|End Sub}}
{{Cl|Sub}} {{Text|EllipseFill|#55FF55}} (CX {{Cl|As}} {{Cl|Integer}}, CY {{Cl|As}} {{Cl|Integer}}, a {{Cl|As}} {{Cl|Integer}}, b {{Cl|As}} {{Cl|Integer}}, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' a = semimajor axis</nowiki>|#919191}}
{{Text|<nowiki>' b = semiminor axis</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|If}} a = {{Text|0|#F580B1}} {{Cl|OR (boolean)|Or}} b = {{Text|0|#F580B1}} {{Cl|Then}} {{Cl|Exit Sub}}
{{Cl|Dim}} h2 {{Cl|As}} {{Cl|_Integer64}}
{{Cl|Dim}} w2 {{Cl|As}} {{Cl|_Integer64}}
{{Cl|Dim}} h2w2 {{Cl|As}} {{Cl|_Integer64}}
{{Cl|Dim}} x {{Cl|As}} {{Cl|Integer}}
{{Cl|Dim}} y {{Cl|As}} {{Cl|Integer}}
w2 = a * a
h2 = b * b
h2w2 = h2 * w2
{{Cl|Line}} (CX - a, CY)-(CX + a, CY), C, BF
{{Cl|DO...LOOP|Do While}} y < b
y = y + {{Text|1|#F580B1}}
x = {{Cl|Sqr}}((h2w2 - y * y * w2) \ h2)
{{Cl|Line}} (CX - x, CY + y)-(CX + x, CY + y), C, BF
{{Cl|Line}} (CX - x, CY - y)-(CX + x, CY - y), C, BF
{{Cl|Loop}}
{{Cl|End Sub}}
{{Cl|Sub}} {{Text|EllipseTilt|#55FF55}} (CX, CY, a, b, ang, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' a = semimajor axis</nowiki>|#919191}}
{{Text|<nowiki>' b = semiminor axis</nowiki>|#919191}}
{{Text|<nowiki>' ang = clockwise orientation of semimajor axis in radians (0 default)</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|For}} k = {{Text|0|#F580B1}} {{Cl|To}} {{Text|6.283185307179586|#F580B1}} + {{Text|.025|#F580B1}} {{Cl|Step}} {{Text|.025|#F580B1}}
i = a * {{Cl|Cos}}(k) * {{Cl|Cos}}(ang) + b * {{Cl|Sin}}(k) * {{Cl|Sin}}(ang)
j = -a * {{Cl|Cos}}(k) * {{Cl|Sin}}(ang) + b * {{Cl|Sin}}(k) * {{Cl|Cos}}(ang)
i = i + CX
j = -j + CY
{{Cl|If}} k <> {{Text|0|#F580B1}} {{Cl|Then}}
{{Cl|Line}} -(i, j), C
{{Cl|Else}}
{{Cl|PSet}} (i, j), C
{{Cl|End If}}
{{Cl|Next}}
{{Cl|End Sub}}
{{Cl|Sub}} {{Text|EllipseTiltFill|#55FF55}} (destHandle&, CX, CY, a, b, ang, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' destHandle& = destination handle</nowiki>|#919191}}
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' a = semimajor axis</nowiki>|#919191}}
{{Text|<nowiki>' b = semiminor axis</nowiki>|#919191}}
{{Text|<nowiki>' ang = clockwise orientation of semimajor axis in radians (0 default)</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|Dim}} max {{Cl|As}} {{Cl|Integer}}, mx2 {{Cl|As}} {{Cl|Integer}}, i {{Cl|As}} {{Cl|Integer}}, j {{Cl|As}} {{Cl|Integer}}
{{Cl|Dim}} prc {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
{{Cl|Dim}} D {{Cl|As}} {{Cl|Integer}}, S {{Cl|As}} {{Cl|Integer}}
D = {{Cl|_DEST (function)|_Dest}}: S = {{Cl|_SOURCE (function)|_Source}}
prc = {{Cl|_RGB32}}({{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|255|#F580B1}})
{{Cl|If}} a > b {{Cl|Then}} max = a + {{Text|1|#F580B1}} {{Cl|Else}} max = b + {{Text|1|#F580B1}}
mx2 = max + max
tef& = {{Cl|_NewImage}}(mx2, mx2)
{{Cl|_Dest}} tef&
{{Cl|_Source}} tef&
{{Cl|For}} k = {{Text|0|#F580B1}} {{Cl|To}} {{Text|6.283185307179586|#F580B1}} + {{Text|.025|#F580B1}} {{Cl|Step}} {{Text|.025|#F580B1}}
i = max + a * {{Cl|Cos}}(k) * {{Cl|Cos}}(ang) + b * {{Cl|Sin}}(k) * {{Cl|Sin}}(ang)
j = max + a * {{Cl|Cos}}(k) * {{Cl|Sin}}(ang) - b * {{Cl|Sin}}(k) * {{Cl|Cos}}(ang)
{{Cl|If}} k <> {{Text|0|#F580B1}} {{Cl|Then}}
{{Cl|Line}} (lasti, lastj)-(i, j), prc
{{Cl|Else}}
{{Cl|PSet}} (i, j), prc
{{Cl|End If}}
lasti = i: lastj = j
{{Cl|Next}}
{{Cl|Dim}} xleft(mx2) {{Cl|As}} {{Cl|Integer}}, xright(mx2) {{Cl|As}} {{Cl|Integer}}, x {{Cl|As}} {{Cl|Integer}}, y {{Cl|As}} {{Cl|Integer}}
{{Cl|For}} y = {{Text|0|#F580B1}} {{Cl|To}} mx2
x = {{Text|0|#F580B1}}
{{Cl|While}} {{Cl|Point}}(x, y) <> prc {{Cl|AND (boolean)|And}} x < mx2
x = x + {{Text|1|#F580B1}}
{{Cl|Wend}}
xleft(y) = x
{{Cl|While}} {{Cl|Point}}(x, y) = prc {{Cl|AND (boolean)|And}} x < mx2
x = x + {{Text|1|#F580B1}}
{{Cl|Wend}}
{{Cl|While}} {{Cl|Point}}(x, y) <> prc {{Cl|AND (boolean)|And}} x < mx2
x = x + {{Text|1|#F580B1}}
{{Cl|Wend}}
{{Cl|If}} x = mx2 {{Cl|Then}} xright(y) = xleft(y) {{Cl|Else}} xright(y) = x
{{Cl|Next}}
{{Cl|_Dest}} destHandle&
{{Cl|For}} y = {{Text|0|#F580B1}} {{Cl|To}} mx2
{{Cl|If}} xleft(y) <> mx2 {{Cl|Then}} {{Cl|Line}} (xleft(y) + CX - max, y + CY - max)-(xright(y) + CX - max, y + CY - max), C, BF
{{Cl|Next}}
{{Cl|_Dest}} D: {{Cl|_Dest}} S
{{Cl|_FreeImage}} tef&
{{Cl|End Sub}}
{{CodeEnd}}
Those are the routines we worked up ages ago for Circles and Ellipses. They should handle whatever you need for them too, and they've been optimized for speed with QB64PE.
Thank you Steve. But OldMoses has given me what I needed (see previous post)
I cleaned that mess up. If you look above your post, you can see the example and routines which I was trying to post instead. That gobbledygook isn't going to be of use to you, or anyone else.
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
07-03-2023, 06:34 AM
(07-03-2023, 06:16 AM)SMcNeill Wrote: Those are the routines we worked up ages ago for Circles and Ellipses. They should handle whatever you need for them too, and they've been optimized for speed with QB64PE.
I had been looking for something like this. Thank you!
Posts: 651
Threads: 96
Joined: Apr 2022
Reputation:
22
(07-03-2023, 06:24 AM)SMcNeill Wrote: (07-03-2023, 06:19 AM)PhilOfPerth Wrote: (07-03-2023, 06:16 AM)SMcNeill Wrote: Code: (Select All)
{{CodeStart}}
{{Cl|Screen}} {{Cl|_NewImage}}({{Text|800|#F580B1}}, {{Text|600|#F580B1}}, {{Text|32|#F580B1}})
{{Cl|Dim}} TransRed {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
{{Cl|Dim}} TransGreen {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
{{Cl|Dim}} TransBlue {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
TransRed = {{Cl|_RGBA}}({{Text|255|#F580B1}}, {{Text|0|#F580B1}}, {{Text|0|#F580B1}}, {{Text|128|#F580B1}})
TransGreen = {{Cl|_RGBA}}({{Text|0|#F580B1}}, {{Text|255|#F580B1}}, {{Text|0|#F580B1}}, {{Text|128|#F580B1}})
TransBlue = {{Cl|_RGBA}}({{Text|0|#F580B1}}, {{Text|0|#F580B1}}, {{Text|255|#F580B1}}, {{Text|128|#F580B1}})
{{Cl|Call}} {{Text|CircleFill|#55FF55}}({{Text|100|#F580B1}}, {{Text|100|#F580B1}}, {{Text|75|#F580B1}}, TransRed)
{{Cl|Call}} {{Text|CircleFill|#55FF55}}({{Text|120|#F580B1}}, {{Text|120|#F580B1}}, {{Text|75|#F580B1}}, TransBlue)
{{Cl|Call}} {{Text|EllipseFill|#55FF55}}({{Text|550|#F580B1}}, {{Text|100|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, TransBlue)
{{Cl|Call}} {{Text|EllipseFill|#55FF55}}({{Text|570|#F580B1}}, {{Text|120|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, TransGreen)
{{Cl|Call}} {{Text|EllipseTilt|#55FF55}}({{Text|200|#F580B1}}, {{Text|400|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|0|#F580B1}}, TransGreen)
{{Cl|Call}} {{Text|EllipseTilt|#55FF55}}({{Text|220|#F580B1}}, {{Text|420|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|3.14|#F580B1}} / {{Text|4|#F580B1}}, TransRed)
{{Cl|Call}} {{Text|EllipseTiltFill|#55FF55}}({{Text|0|#F580B1}}, {{Text|550|#F580B1}}, {{Text|400|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|3.14|#F580B1}} / {{Text|6|#F580B1}}, TransRed)
{{Cl|Call}} {{Text|EllipseTiltFill|#55FF55}}({{Text|0|#F580B1}}, {{Text|570|#F580B1}}, {{Text|420|#F580B1}}, {{Text|150|#F580B1}}, {{Text|75|#F580B1}}, {{Text|3.14|#F580B1}} / {{Text|4|#F580B1}}, TransGreen)
{{Cl|End}}
{{Cl|Sub}} {{Text|CircleFill|#55FF55}} (CX {{Cl|As}} {{Cl|Integer}}, CY {{Cl|As}} {{Cl|Integer}}, R {{Cl|As}} {{Cl|Integer}}, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' R = radius</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|Dim}} Radius {{Cl|As}} {{Cl|Integer}}, RadiusError {{Cl|As}} {{Cl|Integer}}
{{Cl|Dim}} X {{Cl|As}} {{Cl|Integer}}, Y {{Cl|As}} {{Cl|Integer}}
Radius = {{Cl|Abs}}(R)
RadiusError = -Radius
X = Radius
Y = {{Text|0|#F580B1}}
{{Cl|If}} Radius = {{Text|0|#F580B1}} {{Cl|Then}} {{Cl|PSet}} (CX, CY), C: {{Cl|Exit Sub}}
{{Cl|Line}} (CX - X, CY)-(CX + X, CY), C, BF
{{Cl|While}} X > Y
RadiusError = RadiusError + Y * {{Text|2|#F580B1}} + {{Text|1|#F580B1}}
{{Cl|If}} RadiusError >= {{Text|0|#F580B1}} {{Cl|Then}}
{{Cl|If}} X <> Y + {{Text|1|#F580B1}} {{Cl|Then}}
{{Cl|Line}} (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
{{Cl|Line}} (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
{{Cl|End If}}
X = X - {{Text|1|#F580B1}}
RadiusError = RadiusError - X * {{Text|2|#F580B1}}
{{Cl|End If}}
Y = Y + {{Text|1|#F580B1}}
{{Cl|Line}} (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
{{Cl|Line}} (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
{{Cl|Wend}}
{{Cl|End Sub}}
{{Cl|Sub}} {{Text|EllipseFill|#55FF55}} (CX {{Cl|As}} {{Cl|Integer}}, CY {{Cl|As}} {{Cl|Integer}}, a {{Cl|As}} {{Cl|Integer}}, b {{Cl|As}} {{Cl|Integer}}, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' a = semimajor axis</nowiki>|#919191}}
{{Text|<nowiki>' b = semiminor axis</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|If}} a = {{Text|0|#F580B1}} {{Cl|OR (boolean)|Or}} b = {{Text|0|#F580B1}} {{Cl|Then}} {{Cl|Exit Sub}}
{{Cl|Dim}} h2 {{Cl|As}} {{Cl|_Integer64}}
{{Cl|Dim}} w2 {{Cl|As}} {{Cl|_Integer64}}
{{Cl|Dim}} h2w2 {{Cl|As}} {{Cl|_Integer64}}
{{Cl|Dim}} x {{Cl|As}} {{Cl|Integer}}
{{Cl|Dim}} y {{Cl|As}} {{Cl|Integer}}
w2 = a * a
h2 = b * b
h2w2 = h2 * w2
{{Cl|Line}} (CX - a, CY)-(CX + a, CY), C, BF
{{Cl|DO...LOOP|Do While}} y < b
y = y + {{Text|1|#F580B1}}
x = {{Cl|Sqr}}((h2w2 - y * y * w2) \ h2)
{{Cl|Line}} (CX - x, CY + y)-(CX + x, CY + y), C, BF
{{Cl|Line}} (CX - x, CY - y)-(CX + x, CY - y), C, BF
{{Cl|Loop}}
{{Cl|End Sub}}
{{Cl|Sub}} {{Text|EllipseTilt|#55FF55}} (CX, CY, a, b, ang, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' a = semimajor axis</nowiki>|#919191}}
{{Text|<nowiki>' b = semiminor axis</nowiki>|#919191}}
{{Text|<nowiki>' ang = clockwise orientation of semimajor axis in radians (0 default)</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|For}} k = {{Text|0|#F580B1}} {{Cl|To}} {{Text|6.283185307179586|#F580B1}} + {{Text|.025|#F580B1}} {{Cl|Step}} {{Text|.025|#F580B1}}
i = a * {{Cl|Cos}}(k) * {{Cl|Cos}}(ang) + b * {{Cl|Sin}}(k) * {{Cl|Sin}}(ang)
j = -a * {{Cl|Cos}}(k) * {{Cl|Sin}}(ang) + b * {{Cl|Sin}}(k) * {{Cl|Cos}}(ang)
i = i + CX
j = -j + CY
{{Cl|If}} k <> {{Text|0|#F580B1}} {{Cl|Then}}
{{Cl|Line}} -(i, j), C
{{Cl|Else}}
{{Cl|PSet}} (i, j), C
{{Cl|End If}}
{{Cl|Next}}
{{Cl|End Sub}}
{{Cl|Sub}} {{Text|EllipseTiltFill|#55FF55}} (destHandle&, CX, CY, a, b, ang, C {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}})
{{Text|<nowiki>' destHandle& = destination handle</nowiki>|#919191}}
{{Text|<nowiki>' CX = center x coordinate</nowiki>|#919191}}
{{Text|<nowiki>' CY = center y coordinate</nowiki>|#919191}}
{{Text|<nowiki>' a = semimajor axis</nowiki>|#919191}}
{{Text|<nowiki>' b = semiminor axis</nowiki>|#919191}}
{{Text|<nowiki>' ang = clockwise orientation of semimajor axis in radians (0 default)</nowiki>|#919191}}
{{Text|<nowiki>' C = fill color</nowiki>|#919191}}
{{Cl|Dim}} max {{Cl|As}} {{Cl|Integer}}, mx2 {{Cl|As}} {{Cl|Integer}}, i {{Cl|As}} {{Cl|Integer}}, j {{Cl|As}} {{Cl|Integer}}
{{Cl|Dim}} prc {{Cl|As}} {{Cl|_Unsigned}} {{Cl|Long}}
{{Cl|Dim}} D {{Cl|As}} {{Cl|Integer}}, S {{Cl|As}} {{Cl|Integer}}
D = {{Cl|_DEST (function)|_Dest}}: S = {{Cl|_SOURCE (function)|_Source}}
prc = {{Cl|_RGB32}}({{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|255|#F580B1}})
{{Cl|If}} a > b {{Cl|Then}} max = a + {{Text|1|#F580B1}} {{Cl|Else}} max = b + {{Text|1|#F580B1}}
mx2 = max + max
tef& = {{Cl|_NewImage}}(mx2, mx2)
{{Cl|_Dest}} tef&
{{Cl|_Source}} tef&
{{Cl|For}} k = {{Text|0|#F580B1}} {{Cl|To}} {{Text|6.283185307179586|#F580B1}} + {{Text|.025|#F580B1}} {{Cl|Step}} {{Text|.025|#F580B1}}
i = max + a * {{Cl|Cos}}(k) * {{Cl|Cos}}(ang) + b * {{Cl|Sin}}(k) * {{Cl|Sin}}(ang)
j = max + a * {{Cl|Cos}}(k) * {{Cl|Sin}}(ang) - b * {{Cl|Sin}}(k) * {{Cl|Cos}}(ang)
{{Cl|If}} k <> {{Text|0|#F580B1}} {{Cl|Then}}
{{Cl|Line}} (lasti, lastj)-(i, j), prc
{{Cl|Else}}
{{Cl|PSet}} (i, j), prc
{{Cl|End If}}
lasti = i: lastj = j
{{Cl|Next}}
{{Cl|Dim}} xleft(mx2) {{Cl|As}} {{Cl|Integer}}, xright(mx2) {{Cl|As}} {{Cl|Integer}}, x {{Cl|As}} {{Cl|Integer}}, y {{Cl|As}} {{Cl|Integer}}
{{Cl|For}} y = {{Text|0|#F580B1}} {{Cl|To}} mx2
x = {{Text|0|#F580B1}}
{{Cl|While}} {{Cl|Point}}(x, y) <> prc {{Cl|AND (boolean)|And}} x < mx2
x = x + {{Text|1|#F580B1}}
{{Cl|Wend}}
xleft(y) = x
{{Cl|While}} {{Cl|Point}}(x, y) = prc {{Cl|AND (boolean)|And}} x < mx2
x = x + {{Text|1|#F580B1}}
{{Cl|Wend}}
{{Cl|While}} {{Cl|Point}}(x, y) <> prc {{Cl|AND (boolean)|And}} x < mx2
x = x + {{Text|1|#F580B1}}
{{Cl|Wend}}
{{Cl|If}} x = mx2 {{Cl|Then}} xright(y) = xleft(y) {{Cl|Else}} xright(y) = x
{{Cl|Next}}
{{Cl|_Dest}} destHandle&
{{Cl|For}} y = {{Text|0|#F580B1}} {{Cl|To}} mx2
{{Cl|If}} xleft(y) <> mx2 {{Cl|Then}} {{Cl|Line}} (xleft(y) + CX - max, y + CY - max)-(xright(y) + CX - max, y + CY - max), C, BF
{{Cl|Next}}
{{Cl|_Dest}} D: {{Cl|_Dest}} S
{{Cl|_FreeImage}} tef&
{{Cl|End Sub}}
{{CodeEnd}}
Those are the routines we worked up ages ago for Circles and Ellipses. They should handle whatever you need for them too, and they've been optimized for speed with QB64PE.
Thank you Steve. But OldMoses has given me what I needed (see previous post)
I cleaned that mess up. If you look above your post, you can see the example and routines which I was trying to post instead. That gobbledygook isn't going to be of use to you, or anyone else.
Wow!
Thanks Steve; It's shown me some of the incredible things that can be done with this language.
Posts: 176
Threads: 13
Joined: Apr 2022
Reputation:
5
"Gobbledygook". Fascinating... coined by Maury Maverick in the early 1940s... and it still works... lol
Herein ends today's lesson...
May your journey be free of incident. Live long and prosper.
Posts: 2,696
Threads: 327
Joined: Apr 2022
Reputation:
217
(07-03-2023, 07:06 AM)johnno56 Wrote: "Gobbledygook". Fascinating... coined by Maury Maverick in the early 1940s... and it still works... lol
Herein ends today's lesson...
gob·ble·dy·gook
[ˈɡäbəldēˌɡo͞ok]
NOUN
INFORMAL
- language that is meaningless or is made unintelligible by excessive use of abstruse technical terms; nonsense:
Take a look at the pronunciation on that thing! Break it down as "gob-ble-dy-gook" and it's not bad, but what the heck is "[ˈɡäbəldēˌɡo͞ok]" ??
|