'Piston_Acceleration.bas for SmallBASIC v 0.12.11 (B+=MGA) 2018-01-26
' translated and extremely modified from
'// Yabasic 2.78 by Galileo 12/2017
'====================================================================
'
' Instructions - use g for gas and b for brake'
'
'====================================================================
w = xmax: h = ymax
cx = w / 2 : cy = h / 2
dir = -1 : d = 20
while 1
for n = 0 TO 359
cls
if n mod 60 = 0 then k = inkey 'THIS SOLVES PROBLEM OF INKEY SLOW DOWN IN GRAPHICS LOOPS
if k = "g" then
if d - 1 > 0 then d= d - 1
elif k = "b" then
if d+1 < 40 then d = d + 1
end if
k = ""
locate 1, 1 : ? d
x = -COS(rad(n)) * 100 : y = SIN(rad(n)) * 100
dx = cx + x : dy = cy + y
color 9
circle cx, cy, 110, 1, 9 filled
circle cx, cy, 90, 1, 0 filled
star cx, cy, 35, 140, 20, -n
line cx + 150, cy, cx + 450, cy, 15
rect dx + 300 - 30, cy - 40, dx + 300 + 30, cy - 1, 12 filled
color 10
thickline dx, dy, dx + 300, cy - 20, 10
circle dx + 300, cy - 20, 5, 1, 14 filled
circle dx, dy, 5, 1, 14 filled
circle dx + 300, cy - 20, 3, 1, 0
circle dx, dy, 3, 1, 0
showpage
delay d
next
wend
sub thickline(x1, y1, x2, y2, thick) 'this draws a little rectangle
local arr, r, dx, dy, perpA1, perpA2
dim arr()
r = thick/2
dx = x2 - x1
dy = y2 - y1
perpA1 = atan2(dy, dx) + pi/2
perpA2 = perpA1 - pi
arr << x1 + r * cos(perpA1) 'corner 1
arr << y1 + r * sin(perpA1)
arr << x2 + r * cos(perpA1) 'corner 2
arr << y2 + r * sin(perpA1)
arr << x2 + r * cos(perpA2) 'corner 3
arr << y2 + r * sin(perpA2)
arr << x1 + r * cos(perpA2) 'corner 4
arr << y1 + r * sin(perpA2)
arr << x1 + r * cos(perpA1) 'back to first corner
arr << y1 + r * sin(perpA1)
drawpoly arr filled
end
sub star( x, y, rInner, rOuter, nPoints, angleOffset)
' x, y are same as for circle,
' rInner is center circle radius
' rOuter is the outer most point of star
' nPoints is the number of points,
' angleOffset = angle offset IN DEGREES, it will be converted to radians in sub
' this is to allow us to spin the polygon of n sides
pAngle = RAD(360 / nPoints) : radAngleOffset = RAD(angleOffset)
x1 = x + rInner * cos(radAngleOffset)
y1 = y + rInner * sin(radAngleOffset)
for i = 0 to nPoints - 1
x2 = x + rOuter * cos(i * pAngle + radAngleOffset + .5 * pAngle)
y2 = y + rOuter * sin(i * pAngle + radAngleOffset + .5 * pAngle)
x3 = x + rInner * cos((i + 1) * pAngle + radAngleOffset)
y3 = y + rInner * sin((i + 1) * pAngle + radAngleOffset)
line x1, y1, x2, y2, 9
line x2, y2, x3, y3, 9
x1 = x3 : y1 = y3
next
paint x, y, 9
end sub