! circle

let c=1/2
 
def x=cos(c*t)
def y=sin(c*t)
! X = xi + yj

def vx=-c*sin(c*t)
def vy=c*cos(c*t)
! V = vxi + vyj 

def ax=-c*c*cos(c*t)
def ay=-c*c*sin(c*t)
! A = axi + ayj 


sub keypressed
  if key input then
     get key key
     get key key
     if key=ord(" ") then call init
     if key=ord("q" ) then let done=1 else let done=0
  end if
  for count=1 to 1
    let nothing=nothing
  next count
end sub 

sub init
  let done=0
  set mode "egahires"
  close #1
  open #1 : screen 0,1,0,1
  clear
  set color "white"
  box lines 0,1,0,1
  let xmin=-3
  let xmax=-xmin
  let ymin= -2
  let ymax=-ymin
  set window xmin,xmax,ymin,ymax
  plot xmin,0 ; xmax,0
  plot 0,ymin ; 0,ymax
  set color "yellow"
  print "Velocity"
  set color "red"
  print "Acceleration"
end sub

sub vector(x1,x2,y1,y2)
  let m=12
  let d1=(y1-x1)/m
  let d2=(y2-x2)/m
  plot
  plot x1,x2;
  for vect=1 to m
     let x1=x1+d1
     let x2=x2+d2
     plot x1,x2;
  next vect
  box area x1,x1+d1,x2,x2+d2
  plot
end sub

  call init
  let skip= 10
  let dt=1/skip
  let t=0
  do 
    set color "yellow"
    call vector(x,y,x+vx,y+vy)
    set color "red"
    call vector(x,y,x+ax,y+ay)
    set color "green"
    for j=0 to skip
      plot x,y
      let t=t+dt
      call keypressed
    next j
  loop  until done=1

end
