Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.77 KB | None | 0 0
  1. function f(n, phi)
  2.   h = Rose(n);
  3.   [x, y] = Get(h);
  4.   axis([-1, 10, -1, 10]);
  5.   for k = 0:fix(100/(phi*10))
  6.     [x1, y1] = Rotate(x, y, -phi*k);
  7.     [x1, y1] = Move(x1, y1, phi*k, 0);
  8.     Set(h, x1, y1);
  9.     pause(0.1);
  10.   end
  11. end
  12.  
  13. function [h]=Rose(n)
  14.   if mod(n,2)==0
  15.     n=n/2;
  16.   end
  17.   t = linspace(0, 2*pi, 200);
  18.   x = cos(n*t).*cos(t);
  19.   y = cos(n*t).*sin(t);
  20.   h=line(x, y);
  21. end
  22.  
  23. function [x, y] = Get(h)
  24.   x = get(h, 'xdata');
  25.   y = get(h, 'ydata');
  26. end
  27.  
  28. function Set(h, x, y)
  29.   set(h, 'xdata', x);
  30.   set(h, 'ydata', y);
  31. end
  32.  
  33. function [x, y] = Rotate(x, y, phi)
  34.   A = [cos(phi), -sin(phi);sin(phi),cos(phi)];
  35.   xy = [x; y];
  36.   xy = A*xy;
  37.   x = xy(1,:)';
  38.   y = xy(2,:)';
  39. end
  40.  
  41. function [x, y] = Move(x, y, dx, dy)
  42.     x = x+dx;
  43.     y = y+dy;
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement