Guest User

Untitled

a guest
Apr 16th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. function fern
  2.  
  3. shg
  4. clf reset
  5. set(gcf,'color','white','menubar','none', ...
  6. 'numbertitle','off','name','Fractal Fern')
  7. x = [0; 0];
  8. h = plot(x(1),x(2),'.');
  9. darkgreen = [0 2/3 0];
  10. set(h,'markersize',1,'color',darkgreen,'erasemode','none');
  11. axis([-3 3 0 10])
  12. axis off
  13. stop = uicontrol('style','toggle','string','stop', ...
  14. 'background','white');
  15. drawnow
  16.  
  17. p = [ .333 .667 1.00];
  18. A = [ 1/2 0; 1/2 0];
  19. b1 = [0; 0];
  20. b2 = [1/2; 0];e
  21. b3 = [1/4; sqrt(3)/4];
  22.  
  23. cnt = 1;
  24. tic
  25. while ~get(stop,'value')
  26. r = rand;
  27. if r < p(1)
  28. x = A*x + b1;
  29. elseif r < p(2)
  30. x = A*x + b2;
  31. else
  32. x = A*x + b3;
  33. end
  34. set(h,'xdata',x(1),'ydata',x(2));
  35. drawnow
  36. cnt = cnt + 1;
  37. end
  38. t = toc;
  39. s = sprintf('%8.0f points in %6.3f seconds',cnt,t);
  40. text(-1.5,-0.5,s,'fontweight','bold');
  41. set(stop,'style','pushbutton','string','close','callback','close(gcf)')
Add Comment
Please, Sign In to add comment