Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. --PICTURE scene: Ellipse update-demo (anim)
  2. --Demonstrates 'interactive' features.
  3. --by Richard Fhager
  4.  
  5. -- Copyright 2011 Richard Fhager
  6. --
  7. -- This program is free software; you can redistribute it and/or
  8. -- modify it under the terms of the GNU General Public License
  9. -- as published by the Free Software Foundation; version 2
  10. -- of the License. See <http://www.gnu.org/licenses/>
  11.  
  12.  
  13. --
  14. -- rot: Rotation in degrees
  15. -- stp: Step is # of line segments (more is "better")
  16. -- a & b are axis-radius
  17. function ellipse2(x,y,a,b,stp,rot,col)
  18.  local n,m=math,rad,al,sa,ca,sb,cb,ox,oy,x1,y1,ast
  19.  m = math; rad = m.pi/180; ast = rad * 360/stp;
  20.  sb = m.sin(-rot * rad); cb = m.cos(-rot * rad)
  21.  for n = 0, stp, 1 do
  22.   ox = x1; oy = y1;
  23.   sa = m.sin(ast*n) * b; ca = m.cos(ast*n) * a
  24.   x1 = x + ca * cb - sa * sb
  25.   y1 = y + ca * sb + sa * cb
  26.   if (n > 0) then drawline(ox,oy,x1,y1,col); end
  27.  end
  28. end
  29. --
  30.  
  31. setpicturesize(300,300)
  32. setcolor(0,96,96,96)
  33. setcolor(1,255,255,128)
  34.  
  35. r1 = 100
  36. r2 = 50
  37. rt = 0
  38.  
  39. frames = 100
  40.  
  41.  
  42. while (1 < 2) do
  43.  
  44.  r1t = 10 + math.random() * 140
  45.  r2t = 10 + math.random() * 140
  46.  rtt = math.random() * 360
  47.  
  48. for n = 0, frames-1, 1 do
  49.  clearpicture(0)
  50.  
  51.  f2 = n / frames
  52.  f1 = 1 - f2
  53.  
  54.  r1a = r1*f1 + r1t*f2
  55.  r2a = r2*f1 + r2t*f2
  56.  rta = rt*f1 + rtt*f2
  57.  
  58.  --       x,   y,   r1,  r2,  stp, rot, col
  59.  ellipse2(150, 150, r1a, r2a, 50,  rta, 1)
  60.  
  61.   statusmessage('press ESC to stop')
  62.   updatescreen();if (waitbreak(0)==1) then return end
  63.  
  64. end
  65.  
  66.  r1,r2,rt = r1a,r2a,rta
  67.  
  68. end
  69.