Ellipse trouble
#11
(08-24-2022, 12:47 AM)Pete Wrote: This thread reminded me of the old .rip ellipse project. If I recall correctly, Mark, Steve and Bill, and I came up with the gold standard for ellipse drawing speed. It was fun to blow Bill's mind by putting SQR in the formula in such a way it made it faster. Of course, in his defense, Bill's only a theoretical physicist!

Pete Big Grin

I'd be interested in knowing how to speed up something like this:
(it's a rough version of a rotating ellipse)


Code: (Select All)
'ellipse rotate
'james2464



Dim scx, scy As Integer

scx = 800
scy = 600

Screen _NewImage(scx, scy, 32)

Randomize Timer
Const PI = 3.141592654#


Dim c0(100) As Long
Dim x
Dim yy, mm
Dim a, b, y
Dim a1, a2, a3
Dim b1, b2, b3
Dim dir, dv


c0(0) = _RGB(0, 0, 0) 'black
c0(1) = _RGB(255, 255, 255) 'white


Cls




'initial ellipse

a = 50
b = 150
yy = 210
mm = 260
For j = 0 To b
    y = b - j
    x = Sqr((1 - y ^ 2 / b ^ 2) * a ^ 2)
    Line (mm - x, yy - y)-(mm + x, yy - y), c0(1)
    Line (mm - x, yy + y)-(mm + x, yy + y), c0(1)
Next j


a = 40
b = 140
yy = 210
mm = 260
For j = 0 To b
    y = b - j
    x = Sqr((1 - y ^ 2 / b ^ 2) * a ^ 2)
    Line (mm - x, yy - y)-(mm + x, yy - y), c0(0)
    Line (mm - x, yy + y)-(mm + x, yy + y), c0(0)
Next j



'==================================================================

'==================================================================

'==================================================================

'==================================================================

'==================================================================

'==================================================================



'commence crude rotation


a1 = 60
a2 = 58
a3 = 56

b1 = 160
b2 = 158
b3 = 156

yy = 210
mm = 260

dir = 1
dv = 220

Do
    If dir = 1 Then
        a1 = a1 + 1
        a2 = a2 + 1
        a3 = a3 + 1
        If a1 >= b1 Then
            a1 = b1
            dir = 2
        End If
    End If
    If dir = 2 Then
        a1 = a1 - 1
        a2 = a2 - 1
        a3 = a3 - 1
        If a1 <= 1 Then
            a1 = 1
            dir = 1
        End If
    End If


    For j = 0 To b1
        y = b1 - j
        x = Sqr((1 - y ^ 2 / b1 ^ 2) * a1 ^ 2)
        Line (mm - x, yy - y)-(mm + x, yy - y), c0(0)
        Line (mm - x, yy + y)-(mm + x, yy + y), c0(0)
    Next j

    For j = 0 To b2
        y = b2 - j
        x = Sqr((1 - y ^ 2 / b2 ^ 2) * a2 ^ 2)
        Line (mm - x, yy - y)-(mm + x, yy - y), c0(1)
        Line (mm - x, yy + y)-(mm + x, yy + y), c0(1)
    Next j

    For j = 0 To b3
        y = b3 - j
        x = Sqr((1 - y ^ 2 / b3 ^ 2) * a3 ^ 2)
        Line (mm - x, yy - y)-(mm + x, yy - y), c0(0)
        Line (mm - x, yy + y)-(mm + x, yy + y), c0(0)
    Next j



    '======================================================

    'adjust display speed using "w" and "s" keys


    keypress$ = InKey$

    If keypress$ = Chr$(115) Then dv = dv + 2
    If keypress$ = Chr$(119) Then dv = dv - 2

    If dv > 500 Then dv = 500
    If dv < 50 Then dv = 50

    For del1 = 1 To dv * 10000
    Next del1




Loop



End
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



Users browsing this thread: 4 Guest(s)