📄 triangless.m
字号:
function triangless(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);
C0=rand(n+4,3);
C1=rand(n+4,3);
C2=rand(n+4,3);
C3=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,C0,C1,C2,C3);
function [p,r,n,a]=tritri(p,r,n,a,C0,C1,C2,C3);
% 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),C0(n+2,:));
set(pf,'EdgeColor',C0(n+2,:));
if n>0;
[p,r,n,a]=tritri(p,r/2,n-1,a+pi/3,C0,C1,C2,C3);
n=n+1;r=r*2;a=a-pi/3;
[zr(1),r,n,a]=tritri(zr(1),r/4,n-1,a,C1,C0,C2,C3);
n=n+1;r=r*4;
[zr(2),r,n,a]=tritri(zr(2),r/4,n-1,a,C2,C0,C1,C3);
n=n+1;r=r*4;
[zr(3),r,n,a]=tritri(zr(3),r/4,n-1,a,C3,C0,C1,C2);
n=n+1;r=r*4;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -