Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ellipse trouble
#7
(08-23-2022, 05:37 PM)James D Jarvis Wrote: my weak ellipse drawing for you if you don't want to use circle.  My pset method is missing something because I do not recall the math in that area where sqr() can't be called. Bplus is better here. The method using draw actually comes out decent enough.

Code: (Select All)
'badellipse
Screen _NewImage(800, 600, 256)
'pset ellipse
ex = 200
ey = 300
a = 160
b = 50
For y = 0 To 100 Step 0.2
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2 'have to calculate outside sqr() to avoid math error
    If n > 0 Then
        x = Sqr(n)
        PSet (x + ex, y + ey), 15
        PSet (ex - x, y + ey), 15
        PSet (ex - x, ey - y), 15
        PSet (x + ex, ey - y), 15
    End If
Next y


'draw ellipse
ex = 600
ey = 300
a = 160
b = 50
Draw "bm" + Str$(ex) + "," + Str$(ey)
For y = 0 To 100 Step 1 'using larger steps than earlier because draw is slower but laying down line segments
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2
    If n > 0 Then
        x = Sqr(n)
        If y < 1 Then Draw "bm" + Str$(x + ex) + "," + Str$(y + ey)
        Draw "m" + Str$(x + ex) + "," + Str$(y + ey)
    End If
Next y
For y = 100 To 0 Step -1
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2
    If n > 0 Then
        x = Sqr(n)
        If y > 99 Then Draw "bm" + Str$(x + ex) + "," + Str$(y + ey)
        Draw "m" + Str$(ex - x) + "," + Str$(y + ey)
    End If
Next y
For y = 0 To 100 Step 1
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2
    If n > 0 Then
        x = Sqr(n)
        If y < 0 Then Draw "bm" + Str$(x + ex) + "," + Str$(y + ey)
        Draw "m" + Str$(ex - x) + "," + Str$(ey - y)
    End If
Next y
For y = 100 To 0 Step -1
    n = (1 - y ^ 2 / b ^ 2) * a ^ 2
    If n > 0 Then
        x = Sqr(n)
        If y > 99 Then Draw "bm" + Str$(x + ex) + "," + Str$(y + ey)
        Draw "m" + Str$(x + ex) + "," + Str$(ey - y)
    End If
Next y

This is similar to what I was trying to achieve.   I haven't used the "draw" command yet - I'll read up on this.   Thank you.
Reply


Messages In This Thread
Ellipse trouble - by james2464 - 08-23-2022, 03:29 PM
RE: Ellipse trouble - by dcromley - 08-23-2022, 04:07 PM
RE: Ellipse trouble - by james2464 - 08-23-2022, 06:37 PM
RE: Ellipse trouble - by bplus - 08-23-2022, 04:54 PM
RE: Ellipse trouble - by james2464 - 08-23-2022, 06:43 PM
RE: Ellipse trouble - by James D Jarvis - 08-23-2022, 05:37 PM
RE: Ellipse trouble - by james2464 - 08-23-2022, 06:48 PM
RE: Ellipse trouble - by bplus - 08-23-2022, 08:51 PM
RE: Ellipse trouble - by james2464 - 08-23-2022, 11:33 PM
RE: Ellipse trouble - by Pete - 08-24-2022, 12:47 AM
RE: Ellipse trouble - by james2464 - 08-24-2022, 01:59 PM
RE: Ellipse trouble - by Pete - 08-25-2022, 02:23 AM
RE: Ellipse trouble - by james2464 - 08-25-2022, 11:38 AM
RE: Ellipse trouble - by Pete - 08-25-2022, 08:58 PM
RE: Ellipse trouble - by james2464 - 08-25-2022, 10:52 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  trouble filling in a closed vector shape madscijr 31 2,537 11-11-2025, 03:41 PM
Last Post: bplus
  trouble building ansiprint by a740g hsiangch_ong 2 593 01-09-2025, 12:57 AM
Last Post: hsiangch_ong
  Having trouble Windows command line SORT via SHELL GTC 19 4,490 08-26-2023, 04:19 AM
Last Post: GTC
  Drawing an ellipse PhilOfPerth 26 5,143 07-06-2023, 09:30 PM
Last Post: OldMoses
  help moving a sprite in a ellipse Cobalt 8 1,738 07-06-2023, 06:52 PM
Last Post: TerryRitchie

Forum Jump:


Users browsing this thread: 1 Guest(s)