Guest User

Untitled

a guest
Jan 10th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.85 KB | None | 0 0
  1. // room script file
  2.  
  3. float radius;
  4. float radius_step = 3.0;
  5. float angle;
  6. bool alternate_direction = false;
  7. float equidistant = 0.0;
  8. float xc, yc;
  9.  
  10. String text;
  11.  
  12. void Init() {
  13.   text = "This is a test sentence. I'm really curious about the result; I believe I have heard once about this before but seeing it in action is actually quite nice!";
  14.   text = text.UpperCase();
  15.   radius = 10.0;
  16.   angle = 0.0;
  17. }
  18.  
  19. DrawingSurface* backup;
  20. function room_Load()
  21. {
  22.   DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
  23.   backup = ds.CreateCopy();
  24.   ds.Release();
  25. }
  26.  
  27. int last_x, last_y;
  28. void SetCursorTo(this DrawingSurface*, int x, int y) {
  29.   last_x = x;
  30.   last_y = y;
  31. }
  32. void DrawLineTo(this DrawingSurface*, int x, int y) {
  33.   this.DrawLine(last_x, last_y, x, y);
  34.   last_x = x;
  35.   last_y = y;
  36. }
  37.  
  38. void DrawArc(DrawingSurface* ds, float d_angle) {
  39.  
  40.   // to get a smooth arc, use smaller steps the bigger the radius
  41.   float step = 10000.0 / radius;
  42.   float step_angle = d_angle / step;
  43.   int steps = FloatToInt(d_angle / step_angle, eRoundNearest);
  44.   if (steps < 0) steps = -steps;
  45.   int i;
  46.   float da;
  47.   while (i < steps) {
  48.     angle += step_angle;
  49.     da = Maths.DegreesToRadians(angle);
  50.     ds.DrawLineTo(FloatToInt(xc + Maths.Sin(da) * radius, eRoundNearest), FloatToInt(yc + Maths.Cos(da) * radius, eRoundNearest));
  51.     i++;
  52.   }
  53.   while (angle < 0.0) angle += 360.0;
  54.   while (angle >= 360.0) angle -= 360.0;
  55. }
  56.  
  57. void DrawFigure() {
  58.   Init();
  59.   DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
  60.   ds.DrawSurface(backup);
  61.   ds.DrawingColor = Game.GetColorFromRGB(4, 4, 4);
  62.   ds.SetCursorTo(FloatToInt(xc, eRoundNearest), FloatToInt(yc + radius, eRoundNearest));
  63.   int i;
  64.   float d_angle;
  65.   float da;
  66.   int cnt;
  67.   while (i < text.Length) {
  68.     int c = text.Chars[i];
  69.     if (c >= eKeyA && c <= eKeyZ) {
  70.       cnt++;
  71.       d_angle = IntToFloat(c - (eKeyA-1)) * 360.0 / 26.0;
  72.       radius += radius_step;
  73.       da = Maths.DegreesToRadians(angle);
  74.       ds.DrawLineTo(FloatToInt(xc + Maths.Sin(da) * radius, eRoundNearest), FloatToInt(yc + Maths.Cos(da) * radius, eRoundNearest));
  75.       if (alternate_direction && cnt % 2) d_angle = -d_angle;
  76.       if (equidistant > 0.0) {
  77.         float ed_d_angle = (d_angle * 10.0) / radius;
  78.         d_angle = d_angle + (ed_d_angle - d_angle) * equidistant;
  79.       }
  80.       DrawArc(ds, d_angle);
  81.     }
  82.     i++;
  83.   }
  84.   ds.Release();
  85. }
  86.  
  87. void room_AfterFadeIn() {
  88.  
  89.   xc = IntToFloat(System.ViewportWidth / 2);
  90.   yc = IntToFloat(System.ViewportHeight / 2);
  91.  
  92.   DrawFigure();  
  93. }
  94.  
  95. void on_key_press(eKeyCode k) {
  96.  
  97.   if (k == eKeyEscape) QuitGame(0);
  98.    
  99.   if (k == eKeySpace) alternate_direction = !alternate_direction;
  100.  
  101.   if (k == eKeyLeftArrow && equidistant < 1.0) equidistant += 0.1;
  102.   if (k == eKeyRightArrow && equidistant > 0.0) equidistant -= 0.1;
  103.  
  104.   DrawFigure();
  105. }
Advertisement
Add Comment
Please, Sign In to add comment