Advertisement
kevryan

The Incredible Machine - Rope Drawing Code

Mar 14th, 2016
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. void do_conic(color,n,x1,x2,x3,y1,y2,y3)
  2. short color,n;
  3. long x1,x2,x3,y1,y2,y3;
  4. {
  5.    short cur_x, cur_y;
  6.    short old_x, old_y;
  7.    long px, py, rx, ry, nx, ny;
  8.    long t, c;
  9.    long temp;
  10.  
  11.    vm_lcolor = color;
  12.  
  13. //   y2 = y2 << 1;
  14.    
  15.    px = x3 + x1 - (x2<<1);
  16.    py = y3 + y1 - (y2<<1);
  17.    
  18.    rx = (x2 - x1) << (n + 1);
  19.    ry = (y2 - y1) << (n + 1);
  20.  
  21.    temp = n << 1;
  22.    
  23.    nx = x1 << temp;
  24.    ny = y1 << temp;
  25.    
  26.    c = 1 << n;
  27.    
  28.    old_x = (short) (nx>>temp);
  29.    old_y = (short) (ny>>temp);
  30.  
  31.    for ( t = 0; t <= c; t++)
  32.       {
  33.          cur_x = (short) (nx>>temp);
  34.          cur_y = (short) (ny>>temp);
  35.          if (old_x != cur_x || old_y != cur_y)
  36.             {
  37.                vm_line (old_x, old_y, cur_x, cur_y);
  38.                old_x = cur_x;
  39.                old_y = cur_y;
  40.             }
  41.          nx += (rx+(t*2+1)*px);
  42.          ny += (ry+(t*2+1)*py);
  43.       }
  44. }
  45.  
  46.  
  47. void draw_curved_line(x1,y1,x2,y2,len_diff)
  48. short x1,y1,x2,y2,len_diff;
  49. {
  50.    short x_cp,y_cp;
  51.  
  52.    if (len_diff > 4)
  53.    {
  54.       x_cp = (x1+x2)>>1;
  55.       y_cp = ((y1+y2)>>1) + len_diff;
  56.       do_conic(vm_lcolor,4,(long)x1,(long)x_cp,(long)x2,(long)y1,(long)y_cp,(long)y2);
  57.    }
  58.    else
  59.       vm_line(x1,y1,x2,y2);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement