Code: Select all
dim notes$(12),gear(6)
app_init
t=0 ! dt=.1 ! v=.1 ! s=0 ! alfa=0 ! u=0 !thr=0 ! gr=0 ! n=0
loop1: slowdown
if bp("start") then
thr=0.05 ! slider "throttle" value thr ! p=5
else ! goto loop1
end if
loop:
t+=dt
if sc("throttle") then
p=100*slider_value("throttle")
if gr=0 then ntar=3.7*p-3.6
end if
if bp("up") and gr<5 then ! gr+=1 ! gearbox(gr) ! end if
if bp("down") and gr>0 then ! gr-=1 ! gearbox(gr) ! end if
if gr=0 then
n=.5*ntar+.5*n ! rev=.6*n+rnd(2)-1 ! power=0 ! db=0.00025*dt
else
n=min(90,gear(gr)*v)
rev=.6*n
power=(p-0.7)*n-0.27*n^2
db=0.0000011*power*dt
end if
kv=power/v
if v>0 then fric=.02*cos(alfa) else fric=0
drag=1200*(sin(alfa)+fric)+0.044*(v+u)^2
' button "data1" text floor(kv)
a=(kv-drag)/120
' button "data2" text int(10*a)/10
v+=(a+ao)*dt/2 ! ao=a ! v=max(v,.1)
s+=(vo+v)*dt/2 ! vo=v
rmeter("km/hr","r",200,300,150,0,200,3.6*v,0)
rmeter(" rpm","b",550,300,150,0,60,rev,0)
' play_note("18:t",a)
if a<=0 then dt=1 else dt=min(3,1/a)
' door: if not bp("data") then door
goto loop
end
def app_init
graphics ! graphics clear ! fill color .76,.76,.64
option angle degrees
for i=1 to 5 ! read .gear(i) ! next i
for i=0 to 11 ! read .notes$(i) ! next i
data 8,5.5,3.8,2.6,1.8
data "C","C#","D","D#","E","F","F#","G","G#","A","A#","B"
rmeter("km/hr","r",200,300,150,0,200,0,1)
rmeter(" rpm","b",550,300,150,0,60,0,1)
draw size 10
draw arc 200,300,170,-105,90,1
draw arc 550,300,170,-75,90
d=18
draw arc 375,874,770,-90+d,-90-d,1
'draw line 200,130 to 550,130
draw line 200,470 to 550,470
draw size 3
draw rect 360,306 to 390,450
gearbox(0)
slider "throttle" value 0 at 650,840 size 340 angle -90
draw text "Throttle" at 610,880
draw line 600,540 to 600,840
for y=100 to 0 step -20
draw line 600,840-3*y to 620,840-3*y
draw text y at 680,830-3*y
next y
set buttons custom
set buttons font size 60
button "up" text "+" at 50,520 size 80,80
button "down" text "-" at 50,640 size 80,80
draw text "Gear box" at 40,740
set buttons font size 40
button "start" text "Start" at 315,520 size 120,80
set buttons font size 20
' button "data1" text 0 at 315,640 size 120,30
' button "data2" text 0 at 315,680 size 120,30
end def
def gearbox(g)
draw font size 20 ! draw color .6,.6,.6
for y=309 to 410 step 20
draw text str$(floor((409-y)/20)) at 367,y
next y
draw text "R" at 367,429
draw color 0,0,0
draw text g at 367,409-20*g
end def
def play_note(a$,herz)
n$=a$ & freq2note$(herz)
notes set n$ ! notes play
go_on: if notes_time()<.7*notes_length() then go_on
end def
def freq2note$(herz)
if herz<16.35 or herz>7902.13 then return ""
note=int(17.31234*ln(herz)-96.3763)
doct=floor(note/12) ! oct=4+doct ! note-=12*doct
return .notes$(note) & oct
end def
' rmeter function, where:
' tit$ = text, printed on the meter
' col$ = color of meter, "r", "g" , "b" for red, green and blue
' xc and yc = centre of meter on the screen
' rad = size (radius) of the meter
' minval and maxval = lowest and highest value on the scale
' val = the value to be displayed by the meter
' mode=1 : creation of one meter
' mode=0 : use meter to display value
' mode=-1: delete meter from screen
'
def rmeter(tit$,col$,xc,yc,rad,minval,maxval,val,mode)
if mode=-1 then
fill circle xc,yc size rad+2
return
end if
graphics lock
if mode=0 then mode_0
set_col("n")
draw size 3 ! draw circle xc,yc size rad
draw size 4 ! draw circle xc,yc size rad-6
set_col(col$)
draw size 3 ! draw circle xc,yc size rad-3
set_col("n")
draw arc xc,yc,rad-50,130,410
draw size 3
for a=130 to 410 step 28
xs=xc+(rad-50)*cos(a) ! ys=yc+(rad-50)*sin(a)
xe=xc+(rad-42)*cos(a) ! ye=yc+(rad-42)*sin(a)
draw line xs,ys to xe,ye
next a
draw size 1
for a=130 to 410 step 7
xs=xc+(rad-50)*cos(a) ! ys=yc+(rad-50)*sin(a)
xe=xc+(rad-44)*cos(a) ! ye=yc+(rad-44)*sin(a)
draw line xs,ys to xe,ye
next a
delta=(maxval-minval)/10 ! sval=minval
draw font size 15
for a=130 to 410 step 28
xs=xc+(rad-30)*cos(a)-18 ! ys=yc+(rad-30)*sin(a)-10
draw text n2a$(sval,3,0) at xs,ys
sval=sval+delta
next a
draw font size 20
mode_0:
fill circle xc,yc size rad-52
xs=xc+(rad-80)*cos(112) ! ys=yc+(rad-80)*sin(112)
set_col(col$)
fill circle xc,yc size 10 ! draw text tit$ at xs,ys
set_col("n")
if val<minval then val=minval
if val>maxval then val=maxval
beta=130+280*(val-minval)/(maxval-minval)
xs=xc-30*cos(beta) ! ys=yc-30*sin(beta)
xe=xc+(rad-54)*cos(beta) ! ye=yc+(rad-54)*sin(beta)
draw size 6 ! draw line xs,ys to xe,ye
graphics unlock
end def
def set_col(col$)
if col$="r" or col$="R" then
draw color 1,0,0 ! fill color 1,0,0
end if
if col$="g" or col$="G" then
draw color 0,.6,0 ! fill color 0,.6,0
end if
if col$="b" or col$="B" then
draw color 0,0,1 ! fill color 0,0,1
end if
if col$="n" or col$="N" then
draw color 0,0,0 ! fill color .76,.76,.64
end if
enddef
def n2a$(num,lang,dec)
b$=" "
fac=10^dec
num$=floor(fac*num+.5)/fac
tot=lang-len(num$)
if tot<1 then tot=1
a$=substr$(b$,1,tot) & num$
n2a$=a$
end def
def pre_pad$(w,a$)
sp$=" "
tot=w-len(a$)
if tot>0 then pre_pad$=substr$(sp$,1,tot) & a$ else pre_pad$=a$
end def
def bp(a$) = button_pressed(a$)
def sc(a$) = slider_changed(a$)