07-03-2023, 06:19 AM
(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)
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.)
Please visit my Website at: http://oldendayskids.blogspot.com/
Please visit my Website at: http://oldendayskids.blogspot.com/