uses gdip
uses minmidi

Screen 300,330,1
SetCaption "NEWTON"
SetSmoothMode 2
sys font = LoadFont ("verdana",38)

single yacc=.98, yvel=-10, xvel=10, x=20, y=100, r=40

sys hMidi,er
er=midiOutOpen(hMidi, 0, 0, 0, CALLBACK_NULL) ' 0=synth a 2=soft synth
midiOutShortMsg(hMidi, 0xff)         'reset
midiOutShortMsg(hMidi, 0x79B0)       'reset all controllers
midiOutShortMsg(hMidi, 0xC0+0x0E00)  'program assign

'velocity pitch  command channel
'byte3   byte2 nybble2 nybble1
'

While Key(27)=0
ClsColor 55,0,0,255
yvel = yvel + yacc
y = y + yvel
x = x + xvel
iF  y >289 
yvel = -0.9 * yvel 
y =289 
xvel = xvel * 0.9
sys v=trunc(abs(yvel*10))
if v>127 then v=127
if v<10 then v=10
'format: velocity 00 pitch 00 instruction 0 channel 0
midiOutShortMsg(hMidi, v*0x10000+0x005280)
midiOutShortMsg(hMidi, v*0x10000+0x005290)
End iF
iF x >285 
xvel = -xvel
x =285 
midiOutShortMsg(hMidi, 0x704680)
midiOutShortMsg(hMidi, 0x704690)
End iF
iF x<10 
xvel = -xvel 
x = 10 
midiOutShortMsg(hMidi, 0x704C80)
midiOutShortMsg(hMidi, 0x704C90)
End iF
FillOval x, y, r,r, ARGB 155,255,255,255
iF xvel * xvel <0.0001 Then Exit While 
Flip
SetFps 24
Wend
Text font,20,100,"HIT ESCAPE", ARGB 155,255,0,55
WaitKey(27)
midiOutClose(hMidi)
Ends
