# Car Model: "Progress Bar Car"
# Copyright (C) 2024 David Fan
from math import floor
from time import sleep
# f = fuel amount
# e = engine mass
# u = friction
# c = mechanical loss constant
# v = initial velocity
# x = initial position
# d = track length
# b = length of progress bar
f = 100
e = 1
u = .1
c = .1
v = 0
x = 0
d = 500
b = 40
# F = force
# m = mass of fuel tank
# a = acceleration
while(v > 0 or f > 0):
if f > 0:
F = 1
else:
F = 0
m = .1 + .01*f
a = F/(e + m) - u
v = a + v - c*v
x = v + x
f = f - 1
p = floor(b * x/d)
print('a = {:+0.2f}, v = {:+1.1f}, x = {:=+7.2f} {}{}'.format(a,v,x, \
"_" * p, "-" * (b-p)))
if x > d:
print("Finish!")
break
sleep(.2)
if x < d:
print("Did not finish")
Categories