_TITLE "simple spring" 'b+ 2020-08-04 'from: "Mouse down, drag ball, release... Boing" 'B+ 2019-01-08 from
'from: boing.bas for SmallBASIC 2015-07-25 MGA/B+
'2020-08-04 overhaul completely to use 3D spheres instead of lines horizontally across the screen.
' 103 fixes to make look almost right
PRINT "Building spring from spheres hopefully to get 3D coloring effect." PRINT "Check a 250 pixel radius sphere centered on screen, press any to continue..." drawBB 500, 350, 250 'check a good sized sphere
' discover by experiment how to draw a spring with control over variables
y
= _HEIGHT / 2 ' through middle verticallyradius = 100
astart
= _PI(-.5): astop
= _PI(3 / 2) + 2 * da
' so spring starts and ends at 12 o'clock on screen
winds = 10
x = -2 * radius
drawBB sx, sy, 6
x = x + 1 'dx at 1 is perfect for moving 1 radius amount to right in one wind
PRINT x;
"OK x advances exactly 1 radius amount for every 1 wind or circle cycle of angle. " PRINT "Press any to continue..."
'OK to get twice the winds, same radius reduce dx by .5
winds = 20
x = -2 * radius
FOR a
= astart
TO astop
+ (winds
+ 6) * _PI(2) STEP da
'need extra winds to show partials from loops to right drawBB sx, sy, 6
x = x + .5 'cut dx in half
PRINT x;
"OK 20 winds, dx = .5 covers screen. " PRINT "Press any to continue..."
'OK to get 1/5 the winds 2 now, increase dx to 5
winds = 2
x = -2 * radius
FOR a
= astart
TO astop
+ (winds
) * _PI(2) STEP da
'no extra winds needed drawBB sx, sy, 6
x = x + 5 'cut dx in half
PRINT x;
"OK 2 winds, dx = 5 covers screen. " PRINT "Press any to continue..."
' OK do we have enough to make the spring springgy
_TITLE "Simple spring in action! press esc to quit..." wDir = .1: winds = 10: dx = 1
DO 'stretch and compact spring x = -2 * radius
FOR a
= astart
TO astop
+ (winds
+ 13) * _PI(2) STEP da
'have to go way past right border with winds! drawBB sx, sy, 6
x = x + dx 'cut dx in half
winds = winds + wDir
IF winds
> 40 THEN winds
= 40: wDir
= -wDir
IF winds
< 2 THEN winds
= 2: wDir
= -wDir
m = winds / 10
dx = 1 / m
SUB drawBB
(x
, y
, r
) 'this is metal steel ball needs fcirc dcdr = 255 / r
fcirc x
+ i
/ 2 - r
/ 2, y
+ i
/ 2 - r
/ 2, i
, _RGB32(255 - dcdr
* i
)
'from Steve Gold standard
Radius
= ABS(R
): RadiusError
= -Radius: X
= Radius: Y
= 0 LINE (CX
- X
, CY
)-(CX
+ X
, CY
), C
, BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), C
, BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), C
, BF
X = X - 1
RadiusError = RadiusError - X * 2
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