• Remix
  • Share
  • New Entry

on 11 Oct 2024
  • 16
  • 163
  • 0
  • 0
  • 1722
Hallo Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
n=5;r=0.15;bF=10;h=0.4;aL=0.3;lL=0.4;fc=[1,1,0];ec=[0,0,0];mc=[1,0,0];
dMin=0.5;dN=50;dC=rand(dN,3);dS=30;
clf;
persistent p mv;
if isempty(p)
p=genPos(n,dMin);
mv=randn(n,2)*0.01;
end
for i=1:n
p(i,:)=p(i,:)+mv(i,:);
if p(i,1)>1.5||p(i,1)<-1.5, mv(i,1)=-mv(i,1);end
if p(i,2)>1.5||p(i,2)<-2, mv(i,2)=-mv(i,2);end
end
p=enforceMinDist(p,dMin);
hold on;
for i=1:dN
dx=rand*3-1.5;dy=rand*3-2;alpha=abs(sin(f*pi/20+i));
scatter(dx,dy,dS,dC(i,:),'filled','MarkerFaceAlpha',alpha);
end
for i=1:n
theta=linspace(0,2*pi,6);
x=r*cos(theta)+p(i,1);y=r*sin(theta)+p(i,2);
fill(x,y,fc,'EdgeColor','none');
plot([p(i,1),p(i,1)], [p(i,2)-r,p(i,2)-r-h],'Color',fc,'LineWidth',3);
plot([p(i,1)-0.05,p(i,1)-lL],[p(i,2)-r-h,p(i,2)-r-h+sin(f*pi/6)*0.1],'w','LineWidth',2);
plot([p(i,1)+0.05,p(i,1)+lL],[p(i,2)-r-h,p(i,2)-r-h+sin(f*pi/6)*0.1],'w','LineWidth',2);
hy=p(i,2)-r-h/2;
plot([p(i,1)-aL/2,p(i,1)-aL],[hy,hy+sin(f*pi/6)*0.1],'w','LineWidth',2);
plot([p(i,1)+aL/2,p(i,1)+aL],[hy,hy+sin(f*pi/6)*0.1],'w','LineWidth',2);
ex=r*0.4;ey=r*0.2;eLx=p(i,1)-ex;eRx=p(i,1)+ex;eY=p(i,2)+ey;
if mod(f,bF)<bF/2
scatter(eLx,eY,100,ec,'filled');
scatter(eRx,eY,100,ec,'filled');
else
plot([eLx-0.02,eLx+0.02],[eY,eY],'k','LineWidth',2);
plot([eRx-0.02,eRx+0.02],[eY,eY],'k','LineWidth',2);
end
mx=linspace(-0.05,0.05,10)+p(i,1);
my=ones(1,10)*(p(i,2)-0.1);
plot(mx,my,'Color',mc,'LineWidth',2);
end
axis([-1.5 1.5 -2 1.5]);set(gca,'Color','k','XTick',[],'YTick',[]);hold off;
end
function p=genPos(n,dMin)
p=zeros(n,2);
for i=1:n
while true
newP=rand(1,2)*2-1;
if i==1||all(sqrt(sum((p(1:i-1,:)-newP).^2,2))>dMin)
p(i,:)=newP;break;
end
end
end
end
function p=enforceMinDist(p,dMin)
n=size(p,1);
for i=1:n
for j=i+1:n
d=sqrt(sum((p(i,:)-p(j,:)).^2));
if d<dMin
dir=(p(i,:)-p(j,:))/d;
adj=(dMin-d)/2*dir;
p(i,:)=p(i,:)+adj;p(j,:)=p(j,:)-adj;
end
end
end
end
Movie
Audio
Remix Tree