?? triangles.m
字號:
function triangles(n);
% the fractal with triangles;
% n is the number of recursion;
% \copyright: zjliu
% Author's email: zjliu2001@163.com
clc;close all;
if nargin==0;
n=4;
end
rand('state',2);
C=rand(n+4,3);
figure;
axis square equal;hold on;
a=-pi/6;
p=0;
r=1;
[p,r,n,a]=tritri(p,r,n,a,C);
function [p,r,n,a]=tritri(p,r,n,a,C);
% draw a triangle;
% p is the position of the central of triangle;
% r is the radii of triangle;
% n is the the number of recursion;
% a is the angle for triangle;
% C is the matrix of color
z=p+r*exp(i*([0:3]*pi*2/3+a));
zr=p+r*exp(i*([0:3]*pi*2/3+a))/2;
pf=fill(real(z),imag(z),C(n+2,:));
set(pf,'EdgeColor',C(n+2,:));
if n>0;
[p,r,n,a]=tritri(p,r/2,n-1,a+pi/3,C);
n=n+1;r=r*2;a=a-pi/3;
[zr(1),r,n,a]=tritri(zr(1),r/4,n-1,a,C);
n=n+1;r=r*4;
[zr(2),r,n,a]=tritri(zr(2),r/4,n-1,a,C);
n=n+1;r=r*4;
[zr(3),r,n,a]=tritri(zr(3),r/4,n-1,a,C);
n=n+1;r=r*4;
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -