(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
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