# Using MATLAB to draw straight lines and get a simple Zen winding painting, on how boring people always draw straight lines

I watched a video before. Someone split the paper into triangles and then kept drawing straight lines. The patterns on the drawings gradually became more complicated, probably like the following:

The above picture is the effect I simulated with matlab. The process is very simple. It uses the Poisson cloud to build a triangular grid, and then draws straight lines inside the triangle.

For the Poisson cloud collection, you can look at the picture triangulation article:
MATLAB Picture Triangulation Stylization (low poly)

matlab rotated triangle

#### Parameter Description

• rows=560; canvas height
• cols=750; canvas width
• r=min([rows,cols])./6; The distance between two points
• LW=1.2; initial thickness of the line
• k1=1/8; Take the triangle vertex and the other two points to make a new connection at 1/8 of the two points
• k2=0.8; the speed at which the line becomes thinner
• t=20; 3*t lines are drawn inside each triangle

For example, if the parameter r is changed to r=min([rows,cols])./3;, the following figure will be obtained:

#### Complete code

function tris
rows=560;
cols=750;
r=min([rows,cols])./6;
LW=1.2;
k1=1/8;
k2=0.8;
t=20;

fig=figure('units','pixels',...
'position',[20 60 (cols+1) (rows+1)],...
'Color',[1 1 1]);
ax=axes('Units','pixels',...
'parent',fig,...
'Color',[1 1 1],...
'Position',[0 0 (cols+1) (rows+1)],...
'XLim',[-1 cols+1],...
'YLim',[-1 rows+1],...
'XColor','none',...
'YColor','none');
hold(ax,'on')
bkgMat=ones([rows,cols]);
bkgMat(2:(rows-1),2:(cols-1))=0;
bkgMat(1,cols)=0;bkgMat(1,1)=0;bkgMat(rows,1)=0;bkgMat(rows,cols)=0;
[edgeX,edgeY]=find(bkgMat==1);
edgePntList=[edgeY,edgeX];

edgePntList=poissonEdge(rows,cols,edgePntList,r);
pntList=poissonDisk(rows,cols,r,30,edgePntList);
DT=delaunay(pntList(:,1),pntList(:,2));
triplot(DT,pntList(:,1),pntList(:,2),'Color',[0,0,0],'Linewidth',LW);
pause(0.1)

for k=1:size(DT,1)
A=pntList(DT(k,1),:);
B=pntList(DT(k,2),:);
C=pntList(DT(k,3),:);
drawABC(A,B,C,LW,k1,k2,t)
end

%==========================================================================
function resultSet=poissonEdge(m,n,edgeList,R)
preSet=edgeList;
resultSet=[1,1;n,m;1,m;n,1];

times=0;
while times<150
tempPos=randi([1,size(preSet,1)],1);
selectedPnt=preSet(tempPos,:);
dis=sqrt(sum((edgeList-selectedPnt).^2,2));
candidate=dis>=R&dis<=2*R;
pntSet=edgeList(candidate,:);
flag=0;
for j=1:size(pntSet,1)
pnt=pntSet(j,:);
dis=sqrt(sum((resultSet-pnt).^2,2));
if all(dis>=R)
resultSet=[resultSet;pnt];
preSet=[preSet;pnt];
flag=1;
end
end
if flag==1
preSet(tempPos,:)=[];times=0;
else
times=times+1;
end
end
end

function resultSet=poissonDisk(m,n,r,K,edgePntList)
preSet=edgePntList;
resultSet=edgePntList;

times=0;
while times<500
tempPos=randi([1,size(preSet,1)],1);
selectedPnt=preSet(tempPos,:);
theta=rand(K,1).*2*pi;

flag=0;
for j=1:K
pnt=[x(j),y(j)];
if pnt(1)>=1&&pnt(2)>=1&&pnt(1)<=n&&pnt(2)<=m
if size(resultSet,1)==0
resultSet=[resultSet;pnt];
preSet=[preSet;pnt];
flag=1;
else
dis=sqrt(sum((resultSet-pnt).^2,2));
if all(dis>=r)
resultSet=[resultSet;pnt];
preSet=[preSet;pnt];
flag=1;
end
end
end
end
if flag==1
preSet(tempPos,:)=[];times=0;
else
times=times+1;
end
end
end

function drawABC(A,B,C,LW,k1,k2,times)
for i=1:times
b=k1*(C-B)+B;plot([A(1);b(1)],[A(2);b(2)],'color',[0,0,0],'Linewidth',LW);B=b;
pause(0.001)
c=k1*(A-C)+C;plot([B(1);c(1)],[B(2);c(2)],'color',[0,0,0],'Linewidth',LW);C=c;
pause(0.001)
a=k1*(B-A)+A;plot([C(1);a(1)],[C(2);a(2)],'color',[0,0,0],'Linewidth',LW);A=a;
pause(0.001)
LW=LW*k2;
end
end

end