Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function fern
- shg
- clf reset
- set(gcf,'color','white','menubar','none', ...
- 'numbertitle','off','name','Fractal Fern')
- x = [0; 0];
- h = plot(x(1),x(2),'.');
- darkgreen = [0 2/3 0];
- set(h,'markersize',1,'color',darkgreen,'erasemode','none');
- axis([-3 3 0 10])
- axis off
- stop = uicontrol('style','toggle','string','stop', ...
- 'background','white');
- drawnow
- p = [ .333 .667 1.00];
- A = [ 1/2 0; 1/2 0];
- b1 = [0; 0];
- b2 = [1/2; 0];e
- b3 = [1/4; sqrt(3)/4];
- cnt = 1;
- tic
- while ~get(stop,'value')
- r = rand;
- if r < p(1)
- x = A*x + b1;
- elseif r < p(2)
- x = A*x + b2;
- else
- x = A*x + b3;
- end
- set(h,'xdata',x(1),'ydata',x(2));
- drawnow
- cnt = cnt + 1;
- end
- t = toc;
- s = sprintf('%8.0f points in %6.3f seconds',cnt,t);
- text(-1.5,-0.5,s,'fontweight','bold');
- set(stop,'style','pushbutton','string','close','callback','close(gcf)')
Add Comment
Please, Sign In to add comment